Search code examples
rgraphvizpygraphviz

Add round feedback arrow to horizontal graph in Graphviz / DiagrammR


I like to add a feedback arrow to a Graphviz graph, where the ordinary "flow" remains horizontal, but the feedback should be round, like the manually added blue arrow below.

Here is what I tried so far. I use the DiagrammR package for the R language but a suggestion for plain or python Graphviz or would of course also be helpful.

library("DiagrammeR")
grViz("digraph feedback {
         graph [rankdir = 'LR']
           node [shape = box]
             Population
           node [shape = circle]
             Source Sink
           node [shape = none]
             Source -> Growth -> Population -> Death -> Sink
             
             Population -> Growth [constraint = false]
             Death -> Population [constraint = false]
}")

feedback arrow


Solution

  • You can try using the headport and tailport options and indicate "north" for both of these (for Population and Growth).

    The headport is the cardinal direction for where the arrowhead meets the node.

    The tailport is the cardinal direction for where the tail is emitted from the node.

    library("DiagrammeR")
    grViz("digraph feedback {
             graph [rankdir = 'LR']
               node [shape = box]
                 Population
               node [shape = circle]
                 Source Sink
               node [shape = none]
                 Source -> Growth -> Population -> Death -> Sink
                 Population -> Growth [tailport = 'n', headport = 'n', constraint = false]
    }")
    

    Output

    diagrammeR example with curved arrow