rvisualizationgraphvizdirected-acyclic-graphsdiagrammer

Best way to mark forbidden/invalid paths in a DAG with a × on the edge?


I'm trying to draw a causal directed acyclic graph (DAG) for a Mendelian Randomization study, and I want to visually indicate a forbidden path. For example, an edge from node A to B with a "×" drawn across the line to indicate that this path should not be assumed or is invalid.

I'm currently using DiagrammeR::grViz() in R (which wraps Graphviz), and I haven't found a clean way to:

  1. Place a "×" on the edge itself or
  2. Make the edge look like it's "interrupted" or broken

I used DiagrammeR::grViz() in R (which wraps Graphviz) and tried the following:

G -> mid [arrowhead=none, color=red]
mid [label = "×", shape = plaintext, color = red,   fontsize = 30]
mid -> Y [color = red]

This creates a red × in between G and Y, but it's difficult to precisely position it over the edge. The × often floats above or below, and any layout change breaks its alignment.

I also tried adding invisible helper nodes like:

G_top -> mid1 [arrowhead=none, color=red, constraint=false]
mid1 -> U [color=red]
G_top -> G [style=invis]

And tried to align G_top above G using { rank = min; G_top }, but the arrow still doesn't appear to start from the top of node G.

Which tool or library is best suited for this kind of DAG drawing? Any examples appreciated.How to visually represent a "forbidden path?


Solution

  • If you are open to producing native Graphviz output (dot format) and then post-processing it, here is a suggestion.

    Here (https://forum.graphviz.org/t/fun-with-edge-labels/1643) is a Graphviz Forum entry that describes a GVPR (https://www.graphviz.org/pdf/gvpr.1.pdf) program that you can use to adjust edge labels.

    An example:

    digraph place {
      rankdir=LR
     
      Gb -> Yb [label = "×",  color = red,   fontsize = 30 labelOverlay=true]
      Gb -> ab
    
      Gc -> Yc [label = <<table border="0" bgcolor="white"><tr><td>X</td></tr></table>>,  color = red,   fontsize = 20 labelOverlay=true]
      Gc -> ac
    }
    

    Giving:

    enter image description here