2

我正在尝试根据博客文章更多网络布局在 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
4

3 回答 3

2

当前的networkD3官方开发版(v0.4.9000截至2017.09.02)具有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)

它仍在开发中,因此我们将不胜感激

于 2017-09-06T14:34:40.853 回答
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")
于 2017-03-07T06:55:01.420 回答
0

我不确定该tree.cartesian对象在您的代码中应该是什么,但您收到错误“找不到对象”,因为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),此功能(可折叠分支)当前不可用。

于 2017-03-07T10:03:16.000 回答