visNetwork
visNetwork copied to clipboard
HighlightNearest Hierarchical algorithm for only immediately parent edges
Hello,
I am trying to use HighlightNearest to only show the immediate parent edges of a node, similar to using "all" and degree=0. If I use degree=1, I also select further away edges, but selecting degree=0 provides me with no edges at all.
Is it possible to do this somehow?
Many Thanks,
K
Hi,
Using highlightNearest = list(enabled = TRUE, degree = 0), you already have edges started from this nodes highlight. Is it what you want ?
nodes <- data.frame(id = 1:15, label = paste("Label", 1:15),
group = sample(LETTERS[1:3], 15, replace = TRUE))
edges <- data.frame(from = trunc(runif(15)*(15-1))+1,
to = trunc(runif(15)*(15-1))+1)
visNetwork(nodes, edges) %>% visOptions(highlightNearest = list(enabled = TRUE, degree = 0))
Not sure if it's appropriate to piggyback on this question (I can open a new issue if needed), but my question seems extremely similar to the original post.
I'm also having problems with getting the highlightNearest function to display only 1st degree edges, although I would like it to display the 1st degree nodes as well. Using this previous code:
nodes <- data.frame(id = 1:15, label = paste("Label", 1:15),
group = sample(LETTERS[1:3], 15, replace = TRUE))
edges <- data.frame(from = trunc(runif(15)*(15-1))+1,
to = trunc(runif(15)*(15-1))+1)
visNetwork(nodes, edges) %>%
visOptions(highlightNearest = list(enabled = TRUE, degree = 1))
you can create this plot:

How can I set the visOptions so that when I select Label 7, only nodes Label 1, Label 3, Label 8 and Label 14 and the edges connecting these nodes to Label 7 are highlighted?
At the moment, there is an extra highlighted edge connecting Label 1 and Label 14, a self-loop on Label 14 and extra edges from Label 3 to Label 4 and Label 9.
I've played around with using highlightNearest = list(degree = list(from = 1, to = 1), algorithm = "hierarchical") , the labelOnly option and visInteraction(selectConnectedEdges=F) with no luck.
Looks related to #369 .