Search code examples
graphgraphvizdotgraph-drawing

How to put a node in the center of the dot-generated graph


With the following dot code

digraph DG {
    G -> V;
    G -> E;
    G -> P;
    G -> C;
}

I generate the following graph

dot-generated graph

How could I move the node G in the centre? That is I wish to get something like this: wished result

p.s. My experiments with setting the rank of the edge didn't work out.


Solution

  • For the general case, the easiest thing to do is to use twopi or neato instead of dot as your layout engine.

    Twopi:

    twopi layout

    Neato:

    neato

    If you're truly confined to dot, this will give you close to what you want, though you'll have to customize each graph.

    digraph g 
    {
        P -> G [dir=back];
        subgraph clusterGVE {
            {rank=same V; G; E;}
            G -> V [constraint=false];
            G -> E;
            color=invis;
        };
        G -> C;
    }
    

    Dot