1

我想使用带有 R 的 DiagrammeR 节点和边功能创建流程图,而不是使用 graphviz 包装函数。

但是,我不知道如何使边缘笔直以使其美观。

这是看起来像我想要的graphviz解决方案:

# Packages needed for the test
library(DiagrammeR)

# grViz solution
grViz("digraph flowchart {
# node definitions with substituted label text
node [fontname = Helvetica, shape = rectangle]        
tab1 [label = '@@1', group=gr1]
tab2 [label = '@@2', group=gr2]
tab3 [label = '@@3', group=gr3]
invis1 [style = invis, shape=point, width = 0, group=gr1]
invis1a [style = invis, shape=point, width = 0, group=gr2]
invis1b [style = invis, shape=point, width = 0, group=gr3]

# edge definitions with the node IDs
edge [arrowhead='none']
tab1 -> invis1;
invis1a -> invis1 -> invis1b; {rank=same invis1a invis1 invis1b}
edge [arrowhead='normal']
invis1a -> tab2;
invis1b -> tab3; {rank=same tab2 tab3}}

[1]: 'A'
[2]: 'B'
[3]: 'C'
")

这是我尝试使用节点和边解决方案重新创建相同的图:

# Packages needed for the test
library(DiagrammeR)
library(magrittr)

# Node and edge df solution
create_graph() %>% 
  add_node( # id 1
    label = "A",
    type = "group_1",
    node_aes = node_aes(
      style = "filled",
      shape = "rectangle",
      fixedsize = FALSE)
    ) %>% 
  add_node( # id 2
    type = "group_1",
    node_aes = node_aes(
      style = "invisible",
      height = 0,
      width = 0)
    ) %>% 
  add_edge(
    from = 1,
    to = 2,
    edge_aes = edge_aes(
      arrowhead = "none")
    ) %>% 
  add_node( # id 3
    type = "group_2",
    node_aes = node_aes(
      style = "invisible",
      height = 0,
      width = 0)
    ) %>%
  add_edge(
    from = 2,
    to = 3,
    edge_aes = edge_aes(
      arrowhead = "none")
    ) %>% 
  add_node( # id 4
    type = "group_3",
    node_aes = node_aes(
      style = "invisible",
      height = 0,
      width = 0)
    ) %>%
  add_edge(
    from = 2,
    to = 4,
    edge_aes = edge_aes(
      arrowhead = "none")
    ) %>% 
  add_node( # id 5
    label = "B",
    type = "group_2",
    node_aes = node_aes(
      style = "filled",
      shape = "rectangle",
      fixedsize = FALSE)
    ) %>% 
  add_edge(
    from = 3,
    to = 5,
    edge_aes = edge_aes(
      arrowhead = "normal")
    ) %>% 
  add_node( # id 6
    label = "C",
    type = "group_3",
    node_aes = node_aes(
      style = "filled",
      shape = "rectangle",
      fixedsize = FALSE)
    ) %>%
  add_edge(
    from = 4,
    to = 6,
    edge_aes = edge_aes(
      arrowhead = "normal")
    ) %>% 
  render_graph()
4

0 回答 0