繁体   English   中英

如何增加DiagrammeR中节点之间的距离

[英]How to increase distance between nodes in DiagrammeR R

我在R studio中使用DiagrammeR拥有一个不错的图形,但是节点过于聚集在一起。 我到处搜索过,但找不到找到增加它们之间距离的方法。 可以显示给我吗?

这是我的代码:

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

您可以设置不同节点之间箭头的长度:

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

在此处输入图片说明

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

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

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM