graphvizdiagrammer

Manually / adjusting order of edge and path


In the diagram below, I'm looking to have the dashed path/edge going through the middle of the diagram (and therefore the A -> C -> D path will be at the bottom).

I've spent about 2 hours trying to figure this out, including drawing additional paths using "edge [style="invis"]," but to no avail.

Can someone please assist?

DiagrammeR::grViz("digraph {

graph [layout = dot, rankdir = LR]

node [shape = rectangle]        
rec1 [label = 'A']
rec2 [label = 'B']
rec3 [label = 'C']
rec4 [label = 'D']

rec1 -> rec2 
rec1 -> rec3 
rec1 -> rec4 [style = dashed]
rec2 -> rec4 
rec3 -> rec4  
}"
)

enter image description here


Solution

  • digraph {
    // TB rankdir makes things easier
    graph [layout = dot ] 
    graph [nodesep=.9] // spread nodes on same rank
    node [shape = rectangle]
    
    {rank=source
      rec2 [label = "B"]
    }
    {rank=same
      rec1 [label = "A"]
      rec4 [label = "D"]
    }
    { rank=sink
      rec3 [label = "C"]
    }
    rec1 -> rec2 
    rec1 -> rec3 
    rec1 -> rec4 [style = dashed]
    rec2 -> rec4 
    rec3 -> rec4  
    }
    

    Giving:
    enter image description here