3

I am using DiagrammeR R package to draw a flowchart, and below is the code used to generate the mock example:

library(DiagrammeR)
grViz("digraph flowchart {

  # node type 1: starting and ending node
  node [fontname = Helvetica, shape = oval]
  start [label = '@@1']
  node [fontname = Helvetica, shape = oval]
  pro2 [label = '@@6']

  # node type 2: decision
  node [fontname = Helvetica, shape = diamond]
  dec1 [label = '@@2']
  dec2 [label = '@@3']
  node [fontname = Helvetica, shape = diamond]
  dec3 [label = '@@4']

  # node type 3: process 
  node [fontname = Helvetica, shape = rectangle]
  pro1 [label = '@@5']
  node [fontname = Helvetica, shape = rectangle]        
  pro3 [label = '@@7']
  
  # specify which nodes are of the same 'rank' so that they'll be drawn at the same level
  {rank = same; dec2 pro3}
  {rank = same; pro1 dec3}
  
  # edge definitions with the node IDs
  edge[tailclip = true, headclip = true];
  start -> dec1
  dec1 -> dec2 [fontname = Helvetica, label = '', headport = 'n', tailport = 's']
  dec1 -> pro3 [fontname = Helvetica, label = '', headport = 'n', tailport = 'e']
  dec2 -> pro1 [fontname = Helvetica, label = '', tailport = 's']
  dec2 -> pro3 [fontname = Helvetica, label = '']
  pro3 -> dec3 [fontname = Helvetica, label = '', headport = 'n']
  dec3 -> pro2 [fontname = Helvetica, label = '', headport = 'n', tailport = 's']
  dec3 -> pro3 [fontname = Helvetica, label = '', headport = 'e', tailport = 'e']
  pro1 -> dec1 [fontname = Helvetica, label = '', headport = 'w']
  }

  [1]: 'START'
  [2]: 'decision 1'
  [3]: 'decision 2'
  [4]: 'decision 3'
  [5]: 'process 1'
  [6]: 'END'
  [7]: 'process 3'
  ")

The flowchart created looks like this: I am hoping that

  • process 1 could be aligned vertically as "START", "decision 1" and "decision 2" above (currently it is positioned left which looks awkward; also the arrow from decision 2 to process 1 should be straight, not curved...
  • decision 3 and END could be aligned vertically as "process 3" above; also the arrow from process 3 to decision 3 should be straight, not curved...
  • "Good to have" but not required: is there a way to change "curved" arrow into straight arrow? For example, I hope to have arrow tail starts from west side of process 1, straight a little bit horizontally, and then straight vertically to the same level as decision 1, and finally straight horizontally to point to west side of decision 1...

Thank you for your help!

enter image description here

alittleboy
  • 10,616
  • 23
  • 67
  • 107
  • 1
    For 1 and 2, does adding `{rankdir='TB'; start -> dec1 -> dec2 -> pro1}; {rankdir='TB'; pro3 -> dec3 -> pro2};` do what you want (you wll need to remove other edges). Re 3 you probably need to add a dummy/invisible node (these are search terms) – user20650 Dec 30 '20 at 16:45
  • 1
    re 3; https://stackoverflow.com/questions/7115870/creating-straight-edges-in-graphviz/12869546 gives an example. – user20650 Dec 30 '20 at 16:53

0 Answers0