-->

Making the edges curved in visNetwork in R by givi

2019-07-15 04:08发布

问题:

The following R script creates a visNetwork diagram as shown. How to manually change the straight edges to curved edges by giving a curved factor?

One approach that I tried here using the roundness attribute with "smooth" label. However, not able to achieve it.

library(visNetwork)
nodes <- data.frame(id = 1:3,color = c(rep("blue",1), rep("red",1), 
rep("green",1)))
edges <- data.frame(from = c(1,2,3), to = c(2,3,1))
nodes = data.frame(nodes, level = edges$from)
visNetwork(nodes, edges, height = "500px", width = "100%") %>% 
visOptions(highlightNearest = list(enabled = T, degree = 2, hover = T)) %>%
visOptions(highlightNearest = F, nodesIdSelection = F, width = 500, height = 
500,autoResize = F) %>%
visHierarchicalLayout() %>% 
visEdges(shadow = TRUE,
       arrows =list(to = list(enabled = TRUE, scaleFactor = 2)),
       color = list(color = "black", highlight = "red"),
       smooth = list(roundness = 0.3))