Home > Back-end >  diagrammeR - adaptation from "how can I add arms to my flowchart?"
diagrammeR - adaptation from "how can I add arms to my flowchart?"

Time:11-03

I found the following example of diagrammeR here (enter image description here

In my case I have multiple exclusions (m2, m3, m4, m5, m6, m7, m8) between box 2 and 3:

grViz("digraph flowchart {
  # node definitions with substituted label text
  node [fontname = Helvetica, shape = rectangle, fixedsize = false, width = 1] 
  1 [label = 'Box 1']
  2 [label = 'Box 2']
  3 [label = 'Box 3']
  m1 [label = 'm1']
  m2 [label = 'm2']
  m3 [label = 'm3']
  m4 [label = 'm4']
  m5 [label = 'm5']
  m6 [label = 'm6']
  m7 [label = 'm7']
  m8 [label = 'm8']
  
  node [shape=none, width=0, height=0, label='']
  p1 -> 2; p2 -> 3;
  {rank=same; p1 -> m1}
  {rank=same; p2 -> m2}
  {rank=same; p2 -> m3}
  {rank=same; p2 -> m4}
  {rank=same; p2 -> m5}
  {rank=same; p2 -> m6}
  {rank=same; p2 -> m7}
  {rank=same; p2 -> m8}      
  
  edge [dir=none]
  1 -> p1; 2 -> p2;
}")

Currently this gives me: enter image description here

But I would like to have a longer arrow between box 2 and 3 so that all m boxes are one below the other, and not to the right, is this possible? Like:

Box 2
  |--- m2
  |--- m3
  |--- m4
  |--- m5
  |--- m6
  |--- m7
  |--- m8
Box 3

CodePudding user response:

This should get you up and running. Just add more (p3 -> p4... in edge section etc.).

library(DiagrammeR)
grViz("digraph flowchart {
  # node definitions with substituted label text
  node [fontname = Helvetica, shape = rectangle, fixedsize = false, width = 1] 
  1 [label = 'Box 1']
  2 [label = 'Box 2']
  3 [label = 'Box 3']

  m1 [label = 'm1']
  m2 [label = 'm2']
  m3 [label = 'm3']
  
  node [shape=none, width=0, height=0, label='']
  p1 -> 2; p3 -> 3
  {rank=same; p1 -> m1}
  {rank=same; p2 -> m2}
  {rank=same; p3 -> m3}
  
  edge [dir=none, arrowhead=none]
  1 -> p1; 2 -> p2; p2 -> p3
}")

enter image description here

  • Related