带有R的igraph / visNetwork:如何禁用前向链接?

时间:2017-09-17 13:56:20

标签: r igraph visnetwork

以下代码生成了一个很好的网络图:

library(igraph);library(visNetwork);library(dplyr)

set.seed(123)
nnodes <- 10
nnedges <- 20

nodes <- data.frame(id = 1:nnodes)
edges <- data.frame(from = sample(1:nnodes, nnedges, replace = T),
                    to = sample(1:nnodes, nnedges, replace = T))

visNetwork(nodes, edges) %>%
  visIgraphLayout(layout = "layout_in_circle") %>%
  visNodes(shape="circle") %>% 
  visOptions(highlightNearest = list(enabled = T, hover = T), nodesIdSelection = T)

我的问题是:如何禁用从相邻节点离开的边缘(例如,当选择节点8时,我不希望显示3到9的边缘)。 / p>

编辑:添加了库,thx用于解决问题

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

使用来自Djack和wici的评论,我实现了以下解决方案:

library(igraph);library(visNetwork);library(dplyr)

set.seed(123)
nnodes <- 10
nnedges <- 20

nodes <- data.frame(id = 1:nnodes, label = 1:nnodes)
edges <- data.frame(from = sample(1:nnodes, nnedges, replace = T),
                    to = sample(1:nnodes, nnedges, replace = T))

visNetwork(nodes, edges) %>% 
  visIgraphLayout(layout = "layout_in_circle") %>% 
  visNodes(shape="circle") %>% 
  visOptions(highlightNearest = list(enabled = T, hover = T, algorithm="hierarchical"),nodesIdSelection = T) %>% 
  visInteraction(hover = T) 

我希望,那就是你要找的东西。