visNetwork icon indicating copy to clipboard operation
visNetwork copied to clipboard

Highlight Edges with Color Column

Open ramadatta opened this issue 2 years ago • 1 comments

Hi,

In the following code, when you have color column in the edges dataframe, the options hover and highlight does not seems work. Is there anyway to highlight the edges when you have color column in edges do this?

nodes <- data.frame(id = 1:15, label = paste("Label", 1:15),
                    group = sample(LETTERS[1:3], 15, replace = TRUE))

edges <- data.frame(id = 1:15, from = trunc(runif(15)*(15-1))+1,
                    to = trunc(runif(15)*(15-1))+1)

#edges$color <- rainbow(15)

visNetwork(nodes, edges) %>% 
  visIgraphLayout(layout = "layout_in_circle") %>% 
  visEdges(color = list(color = "blue",highlight ="red",hover = "red")) %>% #Hover and Highlight parameters work!
  visInteraction(hover = T)

edges$color <- rainbow(15)

visNetwork(nodes, edges) %>% 
  visIgraphLayout(layout = "layout_in_circle") %>% 
  visEdges(color = list(highlight ="red",hover = "red")) %>% #Hover and Highlight parameters does not work!
  visInteraction(hover = T)

Many thanks in advance!

ramadatta avatar Jul 07 '23 11:07 ramadatta

This solution can also work:

nodes <- data.frame(id = 1:15, label = paste("Label", 1:15),
                    group = sample(LETTERS[1:3], 15, replace = TRUE))

edges <- data.frame(id = 1:15, from = trunc(runif(15)*(15-1))+1,
                    to = trunc(runif(15)*(15-1))+1)

net <- igraph::graph_from_data_frame(d=edges,vertices=nodes,directed = F)
visNetwork::visIgraph(net,layout = "layout_in_circle",type = "full") %>%
  visIgraphLayout(layout = "layout_in_circle") %>% 
  visEdges(color = list(highlight ="red",hover = "red")) %>% 
  visInteraction(hover = T)

BioLaoXu avatar Jul 04 '24 08:07 BioLaoXu