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

1

10

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

Sensation answered 17/9, 2017 at 13:56 Comment(4)
Since your code uses both visNetwork and dplyr it would be helpful for you to include the library statements for those too.Lonni
maybe relatedRelaxation
Does the highlightNearest option algorithm = "hierarchical" what you are looking for?Grandson
This might helps: visNetwork(nodes, edges) %>% visIgraphLayout(layout = "layout_in_circle") %>% visNodes(shape="circle") %>% visOptions(nodesIdSelection = T) %>% visInteraction(hover = T) with nodes <- data.frame(id = 1:nnodes, label = 1:nnodes). It correctly highlights the nodes but hideColor (grey) is not used.Cultured
R
0

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.

Reader answered 15/5, 2018 at 13:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.