我正在尝试根据博客帖子more network layouts在R中实施可折叠网络。但是,我总是得到Object not found
的错误。
devtools::install_github
devtools::install_github("timelyportfolio/networkD3@feature/d3.chart.layout")
library(htmltools)
library(networkD3)
hc = hclust(dist(mtcars))
treeNetwork(
as.treeNetwork(hc, "mtcars")
)
tagList(
lapply(
c("tree.cartesian"
,"tree.radial"
,"cluster.cartesian"
,"cluster.radial"
)
,function(chartType){
hierNetwork(as.treeNetwork(hc), type=chartType, zoomable=T, collapsible=T)
}
)
)
tree.cartesian
编辑1
我们如何将这些图形用于边缘文件来构建网络?示例:
From To
A B
A C
A D
D L
L J
J T
B O
答案 0 :(得分:1)
networkD3的当前官方开发版本(截至2017.09.02的v0.4.9000)有一个新功能treeNetwork
,可以实现可折叠树。
devtools::install_github("christophergandrud/networkD3")
library(networkD3)
hc <- hclust(dist(mtcars))
treeNetwork(hc)
edges <- read.table(header = T, text = "
From To
NA A
A B
A C
A D
D L
L J
J T
B O
")
edges <- as_treenetdf(edges, cols = c(nodeId = "To", parentId = "From"))
treeNetwork(edges)
它仍处于开发阶段,所以我们非常感谢feedback。
答案 1 :(得分:0)
是:
library(networkD3)
to <- c("a","a","a","d","l","j","b")
from <- c("b","c","d","l","j","t","o")
df <-data.frame(to,from)
simpleNetwork(df)
您应该使用官方的networkD3包:
install.packages("networkD3")
答案 2 :(得分:0)
我不确定tree.cartesian
对象应该在您的代码中是什么,但是您得到了错误&#34;找不到对象&#34;因为永远不会在代码中创建tree.cartesian
对象。
话虽如此,如果从lapply
函数中删除tagList
命令,您的代码将会起作用。或者更简洁......
devtools::install_github("timelyportfolio/networkD3@feature/d3.chart.layout")
library(networkD3)
hc = hclust(dist(mtcars))
hierNetwork(as.treeNetwork(hc), type = 'tree.cartesian', zoomable = T, collapsible = T)
# or
hierNetwork(as.treeNetwork(hc), type = 'tree.radial', zoomable = T, collapsible = T)
# or
hierNetwork(as.treeNetwork(hc), type = 'cluster.cartesian', zoomable = T, collapsible = T)
# or
hierNetwork(as.treeNetwork(hc), type = 'cluster.radial', zoomable = T, collapsible = T)
为了清楚起见,你正在使用networkD3的一个分支,据我所知,它已经不再开发了。目前有一些意图将此功能添加到官方networkD3分支,但目前(v0.3.1),此功能(可折叠分支)目前不可用。