可折叠树示例不起作用
问题描述:
我阅读手册,并试图重现以下示例。但R会产生一个错误:可折叠树示例不起作用
Error in collapsibleTree(tree, tooltip = TRUE, attribute = "Value", aggFun = identity) : df must be a data frame
我的问题是这段代码有什么问题。我正在使用R版本3.4.1。谢谢!
# Using a flat relationship-style data frame with tooltips
Relationships <- data.frame(
Parent = c(".",".","A", "A", "A", "B", "B", "C", "E", "E", "F", "K", "K", "M", "M"),
Child = c("A","K","B", "C", "D", "E", "F", "G", "H", "I", "J", "L", "M", "N", "O"),
Value = 1:15
)
tree <- data.tree::FromDataFrameNetwork(Relationships, "Value")
# Define root node value as 0
tree$Value <- 0
# Create tree diagram with the aggregation function of identity
collapsibleTree(tree, tooltip=TRUE, attribute="Value", aggFun=identity)
答
我只是说需要跑了你的代码,没有任何错误,具体如下:
require(data.tree)
require(collapsibleTree)
Relationships <- data.frame(
Parent=c(".",".","A", "A", "A", "B", "B", "C", "E", "E", "F", "K", "K", "M", "M"),
Child=c("A","K","B", "C", "D", "E", "F", "G", "H", "I", "J", "L", "M", "N", "O"),
Value=1:15
)
tree <- data.tree::FromDataFrameNetwork(Relationships, "Value")
tree$Value <- 0
collapsibleTree(tree, tooltip=TRUE, attribute="Value", aggFun=identity)
下面是结果:
这是不是你希望是什么对于?
当您单击节点时,树会打开和关闭... – sconfluentus
有趣。相同的代码不适合我。我正在使用“R版本3.4.1(2017-06-30)”软件包:data.tree“3.4.1”,collapsibleTree“3.4.1”。有什么方法可以将长格式数据(只包含两列,即从&到)转换成一个可以共享用户请求的数据? – ljw5122
我不知道,我确切地使用了你的代码,刚开始时加了'require()'函数。它工作得很好。我可能会检查的一件事。并非所有JS工具在Rstudio图表窗格中都能很好地工作。你有没有尝试将它保存为一个HTML文件,并打开它,看看它是否在浏览器窗口中工作 – sconfluentus