Changing edge direction in dot

JoFrhwld picture JoFrhwld · Mar 24, 2011 · Viewed 22.7k times · Source

I'm trying to draw a pretty simple diagram in dot.

digraph untitled
    {
    rankdir = LR;
    {rank=same; S; A}
    B -> A;
    B -> S;
    A -> A;
    S -> S;
    A -> S ;
    S -> A;
    A -> T;
    S -> T;
}

The results I get is

enter image description here

I really have to change the edge from S -> S, but I would also like to change the orientation of the arrows so they loop from left to right.

Answer

marapet picture marapet · Mar 24, 2011

To change the orientation of any arrow, you may simply use dir=back:

S -> S [dir=back];

But in your case this doesn't seem to be necessary... (see below)

Because of the overlap between the edge S -> S and the A -> S and S -> A edges, I suggest to use only one edge between S and A with an arrowhead on both ends:

digraph g {
    rankdir = LR;
    {rank=same; S; A}
    B -> A -> T;
    B -> S -> T;
    A -> A;
    S -> S;
    A -> S[dir=both];
}

graphviz output