链接指向 forceNetwork 中的左上角,R 中有 networkD3

Links are directed to top left corner in forceNetwork with networkD3 in R

我正在尝试使用 forceNetwork,但链接指向左上角并且链接与预期不符。

library(tidyverse)
library(networkD3)

nodes <- data.frame(name=c("H2o","H2O Driverless AI ","DAI","This is a Mechanized Operations Tracking System","H2O.ai","H2O","H2O is open-source software for Big Data analysis"),group = 1)

nodes <- nodes %>% rowid_to_column("id")

nodes_d3 <- mutate(nodes, id = id - 1)

links <- data.frame(source=c(0,1,2,0,4,5),target=c(1,2,3,4,5,6))

forceNetwork(Links = links, Nodes = nodes_d3, Source = "source", Target = "target", 
              NodeID = "id",Group = "group", opacity = 0.8,arrows = TRUE, zoom = TRUE)

预期是将 h20 作为节点 0 然后连接到 "H2O Driverless AI " 和 H2O.ai.Then H2O Driverless AI > DAI。然后 DAI>This is a Mechanized Operations Tracking System。 H2O.ai> H2O。 H2O>H2O 是大数据分析的开源软件

如有错误请指正

鉴于您的数据,您可能应该使用 NodeID = "name"

更新:

您还必须设置 Value 参数。这是一个可重现的例子...

library(tidyverse)
library(networkD3)

nodes <- data.frame(name=c("H2o","H2O Driverless AI ","DAI","This is a Mechanized Operations Tracking System","H2O.ai","H2O","H2O is open-source software for Big Data analysis"),group = 1)

nodes <- nodes %>% rowid_to_column("id")

nodes_d3 <- mutate(nodes, id = id - 1)

links <- data.frame(source=c(0,1,2,0,4,5),target=c(1,2,3,4,5,6), value = 1)

forceNetwork(Links = links, Nodes = nodes_d3, Source = "source", Target = "target", 
             Value = "value", NodeID = "name", Group = "group", opacity = 0.8,arrows = FALSE, zoom = TRUE)