我正在使用R编程语言。
我有以下图形网络数据:
library(igraph)
library(visNetwork)
from <- c("Boss", "TeamA", "TeamA", "TeamA", "SubteamA1", "SubteamA1", "SubteamA1", "SubteamA2", "SubteamA2", "SubteamA2", "SubteamA3", "SubteamA3", "SubteamA3")
to <- c("TeamA", "SubteamA1", "SubteamA2", "SubteamA3", "employee1", "employee2", "employee3", "employee4", "employee5", "employee6", "employee7", "employee8", "employee9")
a1 = data_frame <- data.frame(from, to)
from <- c("Boss", "TeamB", "TeamB", "TeamB", "SubteamB1", "SubteamB1", "SubteamB1", "SubteamB2", "SubteamB2", "SubteamB2", "SubteamB3", "SubteamB3", "SubteamB3")
to <- c("TeamB", "SubteamB1", "SubteamB2", "SubteamB3", "employee10", "employee11", "employee12", "employee13", "employee14", "employee15", "employee16", "employee17", "employee18")
a2 = data_frame <- data.frame(from, to)
final = rbind(a1, a2)
我将它转换成了一个图形网络,并进行了可视化:
# Convert the data frame to an igraph object
g <- graph_from_data_frame(final, directed=FALSE)
# Plot the graph
plot(g)
# Optional visualization
visIgraph(g)
visIgraph(g) %>%
visHierarchicalLayout(direction = "LR") %>%
visInteraction(navigation = "zoom") %>%
visInteraction(navigation = "drag") %>%
visOptions(selectedBy = "to",
highlightNearest = TRUE,
nodesIdSelection = TRUE)
我的问题: 我一直在尝试找到一种方法,使得当您运行图表时,它只显示屏幕上的一个节点(老板节点) - 当您单击老板节点时,它展开为三个节点(老板,A团队,B团队),如果您点击“ A团队”,它将展开为子团队…但如果您双击,则会折叠回上一个层次。
我能找到的最接近这样的是这里:https://github.com/datastorm-open/visNetwork/issues/307
但是否有更简单的方法在R/javascript中实现呢?最终输出应该是一个(独立的)HTML文件,可以离线查看。
谢谢!
注:
- 我对华丽的 Web 应用程序不感兴趣。
- 我会寻找像这样的东西:D3.js 可折叠力导向图上的标题,如何在 d3.js 中折叠(显示和隐藏)父节点的子节点?,通过选择器编程访问 d3.js v6 可折叠树中的数据,R collapsibleTree:在工具提示中动态添加图像
- 如果它有一个搜索栏和“缩小”选项,那将非常有趣:https://search.r-project.org/CRAN/refmans/collapsibleTree/html/collapsibleTreeNetwork.html,https://cran.r-project.org/web/packages/collapsibleTree/readme/README.html,https://adeelk93.github.io/collapsibleTree/