Graphviz: Edge orientation to and from same node

Viewed 254

I'm creating some multilevel SEM graphs and I'm running into a small problem. The latent variable at the bottom of the graph (labeled "WF") is supposed to have a double-headed edge to and from it but the edge should go under the node. Note the correct orientation of the topmost node. Seems and easy fix but I can find it. Thanks in advance. (BTW, I've provided only a snippet of the original model, but this is sufficient for the purpose.)

digraph stackex {

    {rank=min;
    bf [shape=ellipse]
    bf:nw -> bf:ne [dir = both]}

    {node[shape=square]
      bf -> i1 
      i1[label=X1]
      i1 -> wf [dir=back]}

    {wf [shape=ellipse]
    wf:sw -> wf:se [dir = both]}
}

And here's what it produces:

Graphviz Plot

The double-headed arrow should go under the node labled "WF".

1 Answers

Based on experimentation, it appears that the only way to get

wf:sw -> wf:se [dir = both]

to do what you want is to add

graph [rankdir=TB]

Unfortunately, rankdir affects the entire graph (not just a subgraph or cluster). So you can fix one loop, but you break the other.
The only way I've found to accomplish your goal is to hand-modify the pos of the offending edge (spline). This:

digraph stackex {
    graph [bb="0,0,82.583,216"];
    node [label="\N",
        shape=square
    ];
    bf  [height=0.5,
        pos="41.292,162",
        shape=ellipse,
        width=0.75];
    bf:nw -> bf:ne  [dir=both,
        pos="s,26.292,177 e,56.292,177 22.277,186.17 18.135,200.16 21.792,216 41.292,216 60.792,216 64.448,200.16 60.306,186.17"];
    i1  [height=0.5,
        label=X1,
        pos="41.292,90",
        width=0.5];
    bf -> i1    [pos="e,41.292,108.1 41.292,143.7 41.292,135.98 41.292,126.71 41.292,118.11"];
    wf  [height=0.5,
        pos="41.292,18",
        shape=ellipse,
        width=0.75];
    i1 -> wf    [dir=back,
        pos="s,41.292,71.697 41.292,61.665 41.292,53.054 41.292,43.791 41.292,36.104"];
    wf:se -> wf:sw  [dir=both,
        pos="s,56.292,3 e,26.292,3 
65.002,8.3185 
92.908,0.389 
88.823,-20 
41.292,-20 
-6.2395,-20 
-10.324,0.389 
17.582,8.3185"];
}

And this command neato -n2 -Tpng doubleheaded3.fixed.dot >doubleheaded3.fixed.png Gives this: enter image description here

All in all, I'd suggest the pic/gpic/dpic language. Lower-level, but probably easier to use in the long run.

Related