【问题标题】:Integrating the js code in R to make the visNetwork edges curved在R中集成js代码使visNetwork边缘弯曲
【发布时间】:2018-01-09 05:39:56
【问题描述】:

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

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

【问题讨论】:

    标签: javascript arrays r vis.js visnetwork


    【解决方案1】:

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

    截图:

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多