igraph/visNetwork with R: How to disable forward linking?

496 Views Asked by At

The following code produces a nice network diagram:

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 (e.g. when node 8 is selected, I don't want the edge from 3 to 9 to be shown).

Edit: Libraries added, thx for poining that out

enter image description here enter image description here

1

There are 1 best solutions below

0
On

Using the comment from Djack and wici, I achieved the following solution:

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) 

I hope, thats what you're looking for.