# Draw subgraphs independently

**URL:** <https://forum.graphviz.org/t/draw-subgraphs-independently/725>\
**Category:** Help\
**Created:** [June 29, 2021, 2:26pm UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725 "2021-06-29T14:26:25Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benji](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@Benji](https://forum.graphviz.org/u/Benji)\
**Post date:** [June 29, 2021, 2:26pm UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/1 "2021-06-29T14:26:25Z")

</div>

I’m trying to draw a graph with many subgraphs, but due the global ranking system, the height of each subgraph is influenced by every other subgraph’s layout. Is it possible to decouple them so this doesn’t happen?

This is what I currently have:

 ![image](https://global.discourse-cdn.com/graphviz/original/1X/90d18987e7d31844825778ae3aa7310fcbbf8241.png)

```auto
digraph G {
    subgraph cluster_outer {
        subgraph cluster_1 {
            a [shape=rect, height=1.5]
            b [shape=rect]
            a -> b
        }
        subgraph cluster_2 {
           c [shape=rect]
           d [shape=rect]
           c -> d [color=red]
           color=red
        }
    }
}

```

Notice how the length of the edge `c ->d` is longer than it needs to be, and the subgraph containing `c` and `d` is taller than it needs to be.

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [June 29, 2021, 5:26pm UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/2 "2021-06-29T17:26:01Z")

</div>

Do you ever have edges connecting the clusters, or are the clusters fully independent? If independent, should they be arranged horizontally, vertically, in a grid, or magically (my favorite)?

---

<div class="post-metadata">

**Author:** ![jjlong](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/jjlong/32/887_2.png) [@jjlong](https://forum.graphviz.org/u/jjlong)\
**Post date:** [June 29, 2021, 11:46pm UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/3 "2021-06-29T23:46:55Z")

</div>

There is a graph attribute for DOT named `clusterrank` which sounds like it would activate a feature allowing for independent layouts in the clusters. I tried adding it to your DOT file, but unfortunately it had no effect on the graph.

Here is what the documentation says:

> _clusterrank - Mode used for handling clusters. If clusterrank is “local”, a subgraph whose name begins with “cluster” is given special treatment. The subgraph is laid out separately, and then integrated as a unit into its parent graph, with a bounding rectangle drawn about it. If the cluster has a label parameter, this label is displayed within the rectangle. Note also that there can be clusters within clusters. At present, the modes “global” and “none” appear to be identical, both turning off the special cluster processing._

Maybe I read too much into that description, or maybe `clusterrank` has a bug. Perhaps someone with more knowledge of `clusterrank` can provide some more insights.

---

<div class="post-metadata">

**Author:** ![scnorth](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/scnorth/32/89_2.png) [@scnorth](https://forum.graphviz.org/u/scnorth)\
**Post date:** [June 30, 2021, 11:44am UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/4 "2021-06-30T11:44:42Z")

</div>

If I’m not mistaken, clusterrank=local allows the level (rank) assignment algorithm for a cluster to ignore external edges. The problem is that ranks are still a global property; if some node anywhere in the layout causes a particular level to be higher, that’s a global property that will apply to all nodes and clusters that include that rank.

I don’t believe there’s any workaround.

Sorry about sounding like an infinite audio loop but addressing this would be an interesting project. One could say a lot about allowing fine-grained multilevel nodes in layered graphs (Gordon Woodhull had this working in [dynagraph.org](http://dynagraph.org) if I’m not mistaken) and it would be very desirable to allow nesting generalized subgraphs as big nodes in other layouts, but doing either of these things would affect a lot of the layout code; it’s more than a summer project. Hoping future generations can learn from our mistakes.

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [June 30, 2021, 5:40pm UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/5 "2021-06-30T17:40:09Z")

</div>

Here is a “devil-in-the-details” solution.  
Chop your graph into multiple graphs, each cluster into its own graph. Run each (new) graph through **dot -Tdot** to determine layouts of each separately. Run those results through **gvpack** ([https://www.graphviz.org/pdf/gvpack.1.pdf](https://www.graphviz.org/pdf/gvpack.1.pdf)) to combine them into a single graph. And finally hand that to **neato -n2** to produce an output file. Like so:

```auto
S="";
for f in sub[12].gv; # sub1.gv and sub2.gv are the two created graphs
do 
  T=dot; 
  F=`basename $f .gv`;
  dot -T$T $f >$F.$T; 
  S="$S $F.$T"; 
done; 
gvpack -array_i3 $S |
  neato -n2 -Tpng >O.png

```

Giving:  
 ![O](https://global.discourse-cdn.com/graphviz/original/1X/7c5c98d24791d6e8e0e2467fa2ecb03b15ce7ae0.png)

---

<div class="post-metadata">

**Author:** ![Benji](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@Benji](https://forum.graphviz.org/u/Benji)\
**Post date:** [July 1, 2021, 9:30am UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/6 "2021-07-01T09:30:54Z")

</div>

> [@steveroush](#):
>
> Do you ever have edges connecting the clusters, or are the clusters fully independent? If independent, should they be arranged horizontally, vertically, in a grid, or magically (my favorite)?

I’m not sure what you mean by “magically”.

In my actual use case, clusters are not directly connected (I believe that’s not possible), but nodes are connected between clusters. It is always the top nodes of one cluster being connected to the bottom nodes of another cluster such that the clusters can be seen to form a DAG.

So the arrangement of the clusters is a DAG, if you were to look at it as a bunch of interconnected subgraphs. Whether two clusters are arranged horizontally or vertically depends on their relationship in the DAG.

To make matters a bit more complicated, I’m also working with some elaborate nesting.

Here’s [an example](https://dreampuf.github.io/GraphvizOnline/#digraph%20%7B%0A%20%20graph%20%5Bcompound%3Dtrue%2C%20bgcolor%3Dtransparent%2C%20fontname%3D%22Arial%22%2C%20fontsize%3D16%2C%20fontcolor%3D%22%23412c5a%22%2C%20color%3D%22%23412c5a%22%2C%20fillcolor%3Dtransparent%2C%20style%3D%22filled%22%2C%20penwidth%3D2%2C%20splines%3D%22line%22%2C%20ranksep%3D0.1111111111111111%2C%20nodesep%3D0.3333333333333333%2C%20outputorder%3D%22edgesfirst%22%5D%0A%20%20node%20%5Bfontname%3D%22Arial%22%2C%20fontsize%3D16%2C%20fontcolor%3D%22%23412c5a%22%2C%20color%3D%22%23412c5a%22%2C%20fillcolor%3Dtransparent%2C%20style%3D%22filled%22%2C%20penwidth%3D2%2C%20shape%3D%22box%22%5D%0A%20%20edge%20%5Bfontname%3D%22Arial%22%2C%20fontsize%3D10%2C%20fontcolor%3D%22%23412c5a%22%2C%20color%3D%22%23890c58%22%2C%20dir%3D%22none%22%2C%20penwidth%3D2%5D%0A%20%20subgraph%20%22cluster%20ThermostatSystem%22%20%7B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20rank%3D%22source%22%0A%20%20%20%20%20%20p0%20%5Bid%3D%22e0%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22client%20%3A%20PThermostat%20%E2%93%85%22%5D%0A%20%20%20%20%7D%0A%20%20%20%20subgraph%20cluster%20%7B%0A%20%20%20%20%20%20subgraph%20%22cluster%20ThermostatSystem.thermostat%22%20%7B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20rank%3D%22source%22%0A%20%20%20%20%20%20%20%20%20%20p1%20%5Bid%3D%22e3%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22client%20%3A%20PThermostat%20%E2%93%85%22%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20subgraph%20cluster%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22ThermostatSystem.thermostat%22%20%5Blabel%3D%3CThermostat%3E%2C%20height%3D0%2C%20margin%3D%220.1111111111111111%2C0%22%2C%20penwidth%3D0%2C%20tooltip%3D%22thermostat%20%3A%20Thermostat%22%2C%20id%3D%22e1%22%5D%0A%20%20%20%20%20%20%20%20%20%20penwidth%3D0%0A%20%20%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20%20%20id%3D%22e2%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20rank%3D%22sink%22%0A%20%20%20%20%20%20%20%20%20%20r0%20%5Bid%3D%22e4%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22thermometer%20%3A%20PThermometer%20%E2%93%87%22%5D%0A%20%20%20%20%20%20%20%20%20%20r1%20%5Bid%3D%22e5%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22heater%20%3A%20PHeater%20%E2%93%87%22%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20fillcolor%3D%22%23d4e3f0%22%0A%20%20%20%20%20%20%20%20tooltip%3D%22thermostat%20%3A%20Thermostat%22%0A%20%20%20%20%20%20%20%20id%3D%22e6%22%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20subgraph%20%22cluster%20ThermostatSystem.heater%22%20%7B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20rank%3D%22source%22%0A%20%20%20%20%20%20%20%20%20%20p2%20%5Bid%3D%22e9%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22client%20%3A%20PHeater%20%E2%93%85%22%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20subgraph%20cluster%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22ThermostatSystem.heater%22%20%5Blabel%3D%3CHeater%3E%2C%20height%3D0%2C%20margin%3D%220.1111111111111111%2C0%22%2C%20penwidth%3D0%2C%20tooltip%3D%22heater%20%3A%20Heater%22%2C%20id%3D%22e7%22%5D%0A%20%20%20%20%20%20%20%20%20%20penwidth%3D0%0A%20%20%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20%20%20id%3D%22e8%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20rank%3D%22sink%22%0A%20%20%20%20%20%20%20%20%20%20r2%20%5Bid%3D%22e10%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22statusIndicator%20%3A%20PLed%20%E2%93%87%22%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20fillcolor%3D%22%23d4e3f0%22%0A%20%20%20%20%20%20%20%20tooltip%3D%22heater%20%3A%20Heater%22%0A%20%20%20%20%20%20%20%20id%3D%22e11%22%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20subgraph%20%22cluster%20ThermostatSystem.thermometer%22%20%7B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20rank%3D%22source%22%0A%20%20%20%20%20%20%20%20%20%20p3%20%5Bid%3D%22e14%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22client%20%3A%20PThermometer%20%E2%93%85%22%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20subgraph%20cluster%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22ThermostatSystem.thermometer%22%20%5Blabel%3D%3CThermometer%3E%2C%20height%3D0%2C%20margin%3D%220.1111111111111111%2C0%22%2C%20penwidth%3D0%2C%20tooltip%3D%22thermometer%20%3A%20Thermometer%22%2C%20id%3D%22e12%22%5D%0A%20%20%20%20%20%20%20%20%20%20penwidth%3D0%0A%20%20%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20%20%20id%3D%22e13%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20rank%3D%22sink%22%0A%20%20%20%20%20%20%20%20%20%20r3%20%5Bid%3D%22e15%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22statusIndicator%20%3A%20PLed%20%E2%93%87%22%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20fillcolor%3D%22%23d4e3f0%22%0A%20%20%20%20%20%20%20%20tooltip%3D%22thermometer%20%3A%20Thermometer%22%0A%20%20%20%20%20%20%20%20id%3D%22e16%22%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20subgraph%20%22cluster%20ThermostatSystem.led%22%20%7B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20rank%3D%22source%22%0A%20%20%20%20%20%20%20%20%20%20p4%20%5Bid%3D%22e17%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22client%20%3A%20PLed%20%E2%93%85%22%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20subgraph%20cluster%20%7B%0A%20%20%20%20%20%20%20%20%20%20subgraph%20%22cluster%20ThermostatSystem.led.impl%22%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20rank%3D%22source%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20p5%20%5Bid%3D%22e20%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22client%20%3A%20PLed%20%E2%93%85%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20subgraph%20cluster%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22ThermostatSystem.led.impl%22%20%5Blabel%3D%3CLedGroupImpl%3E%2C%20height%3D0%2C%20margin%3D%220.1111111111111111%2C0%22%2C%20penwidth%3D0%2C%20tooltip%3D%22impl%20%3A%20LedGroupImpl%22%2C%20id%3D%22e18%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20penwidth%3D0%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20id%3D%22e19%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20rank%3D%22sink%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20r4%20%5Bid%3D%22e21%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22led1%20%3A%20PLed%20%E2%93%87%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20r5%20%5Bid%3D%22e22%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22led2%20%3A%20PLed%20%E2%93%87%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20%20%20%20%20fillcolor%3D%22%23d4e3f0%22%0A%20%20%20%20%20%20%20%20%20%20%20%20tooltip%3D%22impl%20%3A%20LedGroupImpl%22%0A%20%20%20%20%20%20%20%20%20%20%20%20id%3D%22e23%22%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20subgraph%20%22cluster%20ThermostatSystem.led.led1%22%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20rank%3D%22source%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20p6%20%5Bid%3D%22e26%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22client%20%3A%20PLed%20%E2%93%85%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20subgraph%20cluster%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22ThermostatSystem.led.led1%22%20%5Blabel%3D%3CLed%3E%2C%20height%3D0%2C%20margin%3D%220.1111111111111111%2C0%22%2C%20penwidth%3D0%2C%20tooltip%3D%22led1%20%3A%20Led%22%2C%20id%3D%22e24%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20penwidth%3D0%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20id%3D%22e25%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20rank%3D%22sink%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22ThermostatSystem.led.led1_bottom_spacer%22%20%5Bwidth%3D0%2C%20height%3D0%2C%20penwidth%3D0%2C%20label%3D%22%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20%20%20%20%20fillcolor%3D%22%23d4e3f0%22%0A%20%20%20%20%20%20%20%20%20%20%20%20tooltip%3D%22led1%20%3A%20Led%22%0A%20%20%20%20%20%20%20%20%20%20%20%20id%3D%22e27%22%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20subgraph%20%22cluster%20ThermostatSystem.led.led2%22%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20rank%3D%22source%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20p7%20%5Bid%3D%22e30%22%2C%20label%3D%22%22%2C%20width%3D0.2916666666666667%2C%20height%3D0.2916666666666667%2C%20fillcolor%3D%22%23aac8e2%22%2C%20tooltip%3D%22client%20%3A%20PLed%20%E2%93%85%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20subgraph%20cluster%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22ThermostatSystem.led.led2%22%20%5Blabel%3D%22Led%5Cn2%22%2C%20height%3D0%2C%20margin%3D%220.1111111111111111%2C0%22%2C%20penwidth%3D0%2C%20tooltip%3D%22led2%20%3A%20Led%22%2C%20id%3D%22e28%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20penwidth%3D0%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20id%3D%22e29%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20rank%3D%22sink%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22ThermostatSystem.led.led2_bottom_spacer%22%20%5Bwidth%3D0%2C%20height%3D0%2C%20penwidth%3D0%2C%20label%3D%22%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20%20%20%20%20fillcolor%3D%22%23d4e3f0%22%0A%20%20%20%20%20%20%20%20%20%20%20%20tooltip%3D%22led2%20%3A%20Led%22%0A%20%20%20%20%20%20%20%20%20%20%20%20id%3D%22e31%22%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20label%3D%3CLedGroup%3E%0A%20%20%20%20%20%20%20%20%20%20penwidth%3D0%0A%20%20%20%20%20%20%20%20%20%20tooltip%3D%22led%20%3A%20LedGroup%22%0A%20%20%20%20%20%20%20%20%20%20margin%3D24%0A%20%20%20%20%20%20%20%20%20%20id%3D%22e32%22%0A%20%20%20%20%20%20%20%20%20%20p4%3As%20-%3E%20p5%3An%20%5Bid%3D%22e33%22%2C%20tooltip%3D%22%20%22%2C%20minlen%3D1%5D%0A%20%20%20%20%20%20%20%20%20%20r4%3As%20-%3E%20p6%3An%20%5Bid%3D%22e34%22%2C%20tooltip%3D%22%20%22%2C%20minlen%3D3%5D%0A%20%20%20%20%20%20%20%20%20%20r5%3As%20-%3E%20p7%3An%20%5Bid%3D%22e35%22%2C%20tooltip%3D%22%20%22%2C%20minlen%3D3%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20rank%3D%22sink%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20margin%3D0%0A%20%20%20%20%20%20%20%20penwidth%3D2%0A%20%20%20%20%20%20%20%20fillcolor%3D%22%23d4e3f0%22%0A%20%20%20%20%20%20%20%20tooltip%3D%22led%20%3A%20LedGroup%22%0A%20%20%20%20%20%20%20%20id%3D%22e36%22%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20label%3D%3CThermostatSystem%3E%0A%20%20%20%20%20%20penwidth%3D0%0A%20%20%20%20%20%20tooltip%3D%22ThermostatSystem%20%3A%20ThermostatSystem%22%0A%20%20%20%20%20%20margin%3D24%0A%20%20%20%20%20%20id%3D%22e37%22%0A%20%20%20%20%20%20p0%3As%20-%3E%20p1%3An%20%5Bid%3D%22e38%22%2C%20tooltip%3D%22%20%22%2C%20minlen%3D1%5D%0A%20%20%20%20%20%20r0%3As%20-%3E%20p3%3An%20%5Bid%3D%22e39%22%2C%20tooltip%3D%22%20%22%2C%20minlen%3D3%5D%0A%20%20%20%20%20%20r1%3As%20-%3E%20p2%3An%20%5Bid%3D%22e40%22%2C%20tooltip%3D%22%20%22%2C%20minlen%3D3%5D%0A%20%20%20%20%20%20r2%3As%20-%3E%20p4%3An%20%5Bid%3D%22e41%22%2C%20tooltip%3D%22%20%22%2C%20minlen%3D3%5D%0A%20%20%20%20%20%20r3%3As%20-%3E%20p4%3An%20%5Bid%3D%22e42%22%2C%20tooltip%3D%22%20%22%2C%20minlen%3D3%5D%0A%20%20%20%20%7D%0A%20%20%20%20%7B%0A%20%20%20%20%20%20rank%3D%22sink%22%0A%20%20%20%20%7D%0A%20%20%20%20margin%3D0%0A%20%20%20%20penwidth%3D2%0A%20%20%20%20fillcolor%3D%22%23d4e3f0%22%0A%20%20%20%20tooltip%3D%22ThermostatSystem%20%3A%20ThermostatSystem%22%0A%20%20%20%20id%3D%22e43%22%0A%20%20%7D%0A%7D%0A) (my project generates diagrams like this). Notice how the height of the “Led” subgraph is dictated by the height of the “Led\n2” subgraph (that is the problem I’m trying to solve).

 ![graphviz (1)](https://global.discourse-cdn.com/graphviz/original/1X/de60a3bd9a16afbd00a8b51c5907675c0965514b.svg)

---

<div class="post-metadata">

**Author:** ![Benji](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@Benji](https://forum.graphviz.org/u/Benji)\
**Post date:** [July 1, 2021, 9:33am UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/7 "2021-07-01T09:33:46Z")

</div>

Thanks. I had feeling the only solution would involve calling Graphviz multiple times. Unfortunately, I need to generate self-contained DOT files.

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [July 1, 2021, 3:48pm UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/8 "2021-07-01T15:48:04Z")

</div>

[sorry for the confusing “magical” comment. It was not an editorial, I keep thinking (incorrectly) that I am a comedian]  
As you noted, you are being caught on the universal nature of **dot** ’s ranking algorithm. I can’t think of a one-step work-around. A general solution would almost undoubtedly be a quite challenging enhancement to **dot**. I kind of, maybe think I can envision an enhancement that would solve the more special-case you describe (clusters only connected via top/bottom nodes). But even it would be fiddly at best.  
The one thing I would note is that _for the “led” example you link to_, expanding node width and making the “Led\n2” text fit on one line would solve the problem - locally.

p.s. I like your graph’s look/style

---

<div class="post-metadata">

**Author:** ![jjlong](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/jjlong/32/887_2.png) [@jjlong](https://forum.graphviz.org/u/jjlong)\
**Post date:** [July 2, 2021, 3:34pm UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/9 "2021-07-02T15:34:22Z")

</div>

It is possible to connect clusters. You can connect nodes to clusters, and clusters to clusters. There is a good writeup [here](https://stackoverflow.com/questions/2012036/graphviz-how-to-connect-subgraphs) on StackOverflow of how to do it.

---

<div class="post-metadata">

**Author:** ![schmoo2k](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/schmoo2k/32/29_2.png) [@schmoo2k](https://forum.graphviz.org/u/schmoo2k)\
**Post date:** [July 3, 2021, 5:16am UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/10 "2021-07-03T05:16:49Z")

</div>

The top example here has node, cluster links: [Sample Pipeline / Gordon Smith / Observable (observablehq.com)](https://observablehq.com/d/591ce8dae339f6ba)

---

<div class="post-metadata">

**Author:** ![Benji](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@Benji](https://forum.graphviz.org/u/Benji)\
**Post date:** [July 6, 2021, 1:49pm UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/11 "2021-07-06T13:49:25Z")

</div>

It is a shame this can’t be done, but thank you anyway for your explanations.

---

<div class="post-metadata">

**Author:** ![eyssette](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/eyssette/32/103_2.png) [@eyssette](https://forum.graphviz.org/u/eyssette)\
**Post date:** [August 7, 2021, 8:48pm UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/12 "2021-08-07T20:48:56Z")

</div>

A solution would be to use ranksep=0.1 and change the len of specific edges, with minlen.

```auto
digraph G {
ranksep=0.1
    subgraph cluster_outer {
        subgraph cluster_1 {
            a [shape=rect, height=1.5]
            b [shape=rect]
            a -> b[minlen=2]
        }
        
        subgraph cluster_2 {
            
           c [shape=rect]
           d [shape=rect]
           c -> d [color=red]
           color=red
        }
    }
}

```

![graphviz](https://global.discourse-cdn.com/graphviz/original/1X/f18f1b7eb0414d77810e45d523a8585720a1c85f.png)

---

<div class="post-metadata">

**Author:** ![Benji](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@Benji](https://forum.graphviz.org/u/Benji)\
**Post date:** [September 22, 2021, 10:55am UTC](https://forum.graphviz.org/t/draw-subgraphs-independently/725/13 "2021-09-22T10:55:26Z")

</div>

I don’t believe that’s a very robust solution. If I take away one subgraph, it becomes obvious that `ranksep` really is 0.1.

![image](https://global.discourse-cdn.com/graphviz/original/1X/0766ed07fac60fba2d26b9f014eef856f9b5853f.png)

```auto
digraph G {
    ranksep=0.1
    subgraph cluster_outer {
        subgraph cluster_2 {
          c [shape=rect]
          d [shape=rect]
          c -> d [color=red]
          color=red
        }
    }
}

```

I’m really looking for something that will allow me to automatically generate graphs, sometimes with dozens of nested and interconnected subgraphs.

Thank you anyway.
