Integrating the js code in R to make the visNetwork edges curved

本小妞迷上赌 提交于 2019-11-28 12:41:17

问题


the script below creates the visNetwork as shown in the visualization below. I want a functionality to make the edge "1" and edge "3" curved. I am attaching the js code that can be used to achieve this. However, please help me to integrate the same code in R. Thanks.

nodes <- data.frame(id = 1:4)
edges <- data.frame(from = c(2,4,3,2), to = c(1,2,4,3), label = 1:4)
edges <- data.frame(edges,edges$from)
visNetwork(nodes, edges, width = "100%") %>% 
visEdges(arrows =list(to = list(enabled = TRUE, scaleFactor = 2)),
       color = list(color = "lightblue", highlight = "red")) %>% 
visHierarchicalLayout()

JS Code

{from: 2, to: 1, arrows: 'to', label: "1", smooth: {type: "curvedCCW", 
roundness: 0.4}},
{from: 3, to: 4, arrows: 'to', label: "3", smooth: {type: "curvedCCW", 
roundness: 0.2}},


回答1:


Updated code with listed paramaters of smooth:

library(visNetwork)
nodes <- data.frame(id = 1:4)
edges <- data.frame(from = c(2,4,3,2), to = c(1,2,4,3), label = 1:4, smooth = list(enabled = F, type ='curvedCW', roundness = 0.2))
edges <- data.frame(edges,edges$from)

#enable smooth for the edges you like

edges$smooth.enabled[edges$label==1] = T
edges$smooth.enabled[edges$label==3] = T
visNetwork(nodes, edges, width = "100%") %>% 
  visEdges(arrows =list(to = list(enabled = TRUE, scaleFactor = 2)),
           color = list(color = "lightblue", highlight = "red")) %>% 
  visHierarchicalLayout()

Screenshot:



来源:https://stackoverflow.com/questions/48162029/integrating-the-js-code-in-r-to-make-the-visnetwork-edges-curved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!