在R中集成js代码以使visNetwork边缘弯曲 [英] Integrating the js code in R to make the visNetwork edges curved

查看:118
本文介绍了在R中集成js代码以使visNetwork边缘弯曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的脚本创建了visNetwork,如下图所示。我想要一个功能,使边缘1和边缘3弯曲。我附加了可用于实现此目的的js代码。但是,请帮我在R中集成相同的代码。谢谢。

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代码

{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}},

推荐答案

使用列出的参数更新代码

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()

屏幕截图:

这篇关于在R中集成js代码以使visNetwork边缘弯曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆