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

moabit21
  • 639
  • 8
  • 20
  • Since your code uses both `visNetwork` and `dplyr` it would be helpful for you to include the library statements for those too. – G5W Sep 17 '17 at 14:09
  • [maybe related](https://github.com/datastorm-open/visNetwork/issues/160) – lukeA Sep 17 '17 at 15:17
  • 1
    Does the `highlightNearest` option `algorithm = "hierarchical"` what you are looking for? – wici May 14 '18 at 05:47
  • 1
    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. – DJack May 14 '18 at 13:52

1 Answers1

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.

SeGa
  • 9,454
  • 3
  • 31
  • 70