首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在DiagrammeR R中增加节点间的距离

如何在DiagrammeR R中增加节点间的距离
EN

Stack Overflow用户
提问于 2016-06-27 13:48:49
回答 1查看 1.7K关注 0票数 1

我在R演播室中有一个很好的DiagrammeR图,但是节点太聚集,无法收集。我到处都找遍了,但我找不到办法扩大他们之间的距离。能给我看一下吗?

这是我的代码:

代码语言:javascript
复制
library(magrittr)
library(DiagrammeR)

# Create a simple NDF
nodes <- create_nodes(nodes = c("Index", "Surveillance", "Intervention","Lost"),
                     label = TRUE,
                     fontsize=55,
                     type = "lower",
                     style = "filled",
                     color = "aqua",
                     shape = c("circle", "circle",
                               "rectangle", "rectangle"),
                     data = c(30.5, 2.6, 9.4, 2.7))

edges <- create_edges(from = c("Index", "Surveillance","Surveillance","Intervention", "Surveillance", "Index" ), 
                  to = c("Surveillance", "Intervention","Surveillance","Intervention", "Lost", "Lost"),
                  rel = c(99, 6.7, 99, 99, 27, 22),
                  arrowhead = rep("normal", 6),
                  color = c("green", "green", "red", "red", "red", "red"))


graph <-
  create_graph(
    nodes_df = nodes,
    edges_df = edges,
    graph_attrs <-
      c("layout = dot","overlap = FALSE","outputorder = edgesfirst"),
    node_attrs <-
      c("shape = circle",
        "fixedsize = TRUE",
        "width = 100",
        "penwidth = 1",
        "color = DodgerBlue",
        "style = filled",
        "fillcolor = Aqua",
        "alpha_fillcolor = 0.5",
        "fontname = Helvetica",
        "fontcolor = Black"),
    edge_attrs = "color = gray20")

# View the graph
render_graph(graph,layout=constant,output="visNetwork")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-27 14:03:50

您只需为不同节点之间的箭头设置长度:

代码语言:javascript
复制
edges <- create_edges(from = c("Index", "Surveillance","Surveillance","Intervention", "Surveillance", "Index" ), 
                      to = c("Surveillance", "Intervention","Surveillance","Intervention", "Lost", "Lost"),
                      rel = c(99, 6.7, 99, 99, 27, 22),
                      arrowhead = rep("normal", 6),
                      color = c("green", "green", "red", "red", "red", "red"), 
                      length = c(200,200,50,50,200,200))

或者您可以为每个节点定义一个精确的点:

代码语言:javascript
复制
nodes <- create_nodes(nodes = c("Index", "Surveillance", "Intervention","Lost"),
                     label = TRUE,
                     fontsize = 55,
                     type = "lower",
                     style = "filled",
                     color = "aqua",
                     shape = c("circle", "circle",
                               "rectangle", "rectangle"),
                     data = c(30.5, 2.6, 9.4, 2.7),
                     x = c(-80,80,-80,80),
                     y = c(-80,80,80,-80))

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38055696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档