Search code examples
rflowchartdiagrammer

flow chart with both horizontal and vertical nodes


I want to create a flow chart that contains both vertical and horizontal flowing nodes.

I have attempted to do this using library(DiagrammeR) with this code.

  `library(DiagrammeR)

   grViz(diagram = "digraph flowchart {
   node [fontname = helvetica, fontsize = 9, shape = rounded, penwidth = 1.0]
   graph[nodesep = 0.5]
   tab1 [label = '@@1']
   tab2 [label = '@@2']
   tab3 [label = '@@3']
   tab4 [label = '@@4']
   tab5 [label = '@@5']
   tab6 [label = '@@6']
   tab7 [label = '@@7']
   tab8 [label = '@@8']
   
   tab1 -> tab3;
   tab2 -> tab4;
   tab3 -> tab4;tab4 -> tab5;
   tab5 -> tab6;
   tab6 -> tab7;
   tab7 -> tab8;}

   [1]: 'KNOWN MAKE (N=500000)'
   [2]: 'MEN (N=400000)'
   [3]: 'UNKNOWN MAKE (N=12000)'
   [4]: 'CAR (N=488174)'
   [5]: 'PLANE (N=462050)'
   [6]: 'HORSE (N=442247)'
   [7]: 'BIKE (N=441912)'
  [8]: 'WALK (N=441343)'")

But, this only produces vertical flowing nodes- output included below. flow chart - not desired output

I want the arrow that leads to ''WALK'' to flow from left to right (horizontal) of ''BIKE'' rather than down (vertical).

Any help will be appreciated. I have updated this to include a desired output. enter image description here Desired Output


Solution

  • Update: This was a lot of try and error, but now I think we got it: (removed first answer):

    library(DiagrammeR)
    
    
    grViz(diagram = "digraph flowchart {
      node [fontname = helvetica, fontsize = 9, shape = rounded, penwidth = 1.0]
      graph[nodesep = 0.5, rankdir = TB]
      tab1 [label = '@@1']
      tab2 [label = '@@2']
      tab3 [label = '@@3']
      tab4 [label = '@@4']
      tab5 [label = '@@5']
      tab6 [label = '@@6']
      tab7 [label = '@@7']
      tab8 [label = '@@8' shape=rectangle color=black style='filled,bold' fillcolor=white];
      subgraph {
        rank = same;
        tab7;
        tab8 [color=black fillcolor=white style='filled,bold'];
      }
      
      tab1 -> tab3;
      tab2 -> tab4;
      tab3 -> tab4;
      tab4 -> tab5;
      tab5 -> tab6;
      tab6 -> tab7;
      tab7 -> tab8;
      
    }
      
    [1]: 'KNOWN MAKE (N=500000)'
    [2]: 'MEN (N=400000)'
    [3]: 'UNKNOWN MAKE (N=12000)'
    [4]: 'CAR (N=488174)'
    [5]: 'PLANE (N=462050)'
    [6]: 'HORSE (N=442247)'
    [7]: 'BIKE (N=441912)'
    [8]: 'WALK (N=441343)'")
    

    enter image description here