Search code examples
graphvizdot

Force different ranks for subgraphs in Dot (graphviz)


I have a dot graph with two subgraphs with the option "rank=same"

digraph G {
rankdir=LR;
newrank=true;
splines=false;

subgraph  {
rank=same;
a1;
b1;
c1;
}

subgraph  {
rank=same;
a2;
b2;
c2;
}
}

It gives me the following :

enter image description here

However, how could I force the ranks to be different, i.e. for a1, b1, c1 to be in a different rank than a2, b2, c2 ?


Solution

  • Use an invisible edge:

    digraph G {
    rankdir=LR;
    //newrank=true;  // only applies to clusters
    splines=false;    
    subgraph  {
    rank=same;
    a1;
    b1;
    c1;
    }
    subgraph  {
    rank=same;
    a2;
    b2;
    c2;
    }
    a1 -> a2 [style=invis]
    }
    

    Giving:
    enter image description here