10

以下代码生成了一个漂亮的网络图:

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)

My question is: How can I disable that edges that leave from a neighboring node are displayed as well (eg when node 8 is selected, I don't want the edge from 3 to 9 to be shown).

编辑:添加了库,感谢您指出这一点

在此处输入图像描述 在此处输入图像描述

4

1 回答 1

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) 

我希望,这就是你要找的。

于 2018-05-15T13:07:22.990 回答