Search code examples
visualizationgraphvizdotsubgraphneato

Clustering subgraphs with singleton/unconnected nodes using neato engine in Graphviz


I'm hoping to generate two subgraphs with the Graphviz neato engine. One subgraph will contain nodes that are connected to each other, the other will contain singleton nodes that aren't connected to any other nodes. I have adjusted this example from the Graphviz website below:

digraph G {
    node [shape = circle];
    edge [arrowhead = normal, label="", color="#919191"];

    subgraph cluster_0 {
        color=lightgrey;
        label="Singletons";
        a0;
        a1;
        a2;
        a3;
    }

    subgraph cluster_1 {
        color=lightgrey;
        label="Non-singletons";
        b0 -> b1;
        b2 -> b3;
    }
}

Which gives the following graph when processed with the neato engine where the nodes in each subgraph aren't clustered together.

neato -Tpng test.dot > test_neato.png

enter image description here

Processing with the dot engine gives alright results but I need to generate networks with a large number of nodes and the neato engine is more suitable in this format.

dot -Tpng test.dot > test_dot.png

enter image description here

I would like the borders, titles, and clustering (as shown in the example using dot above) but using the neato engine for positioning the nodes. Is there a way to do this in Graphviz?

Thanks in advance for the help.


Solution

  • This seems to be possible with the fdp engine according to discussion in this thread.

    The following command produces a figure that is satisfactory.

    fdp -Tpng test.dot > test_dot.png
    

    enter image description here