Search notes:

Graphviz: subgraph

A subgraph whose ID starts with cluster_ is a cluster
The only attribute that is applicable on a non-cluster subgraph is rank.

Creating subgraphs

A subgraph is enclosed in opening and closing curly parentheses.
Optionally, the subgraph can be explicitly stated as such with the keyword subgraph. If this keyword is used, the subgraph might also optionally be named with an ID.
Finally, if the ID starts with cluster, the subgraph becomes a cluster.
The following example creates four subgraphs that demonstrate each of the four variations:
digraph XYZ {
                       { A -> B }
  subgraph             { C -> D } 
  subgraph named       { E -> F }
  subgraph cluster_xyz { G -> H }
}
Github repository about-Graphviz, path: /elems/subgraph/with-without-keyword.dot

A subgraph allows to specify attributes for elements within the subgraph

Attributes that are set in an attribute statement are valid within the subgraph that they're defined in:
digraph A {

//
// Specify an attribute outside of any subgraph.
// It affects all nodes in the intere graph
   node [shape=box]

   {
   //
   // Specifiy a couple of attributes that
   // affect only the nodes within the
   // current subgraph:
   //
      node [color=blue fontcolor=blue]
      A
      B
   }
   {
   //
   // Again, a couple of attributes for
   // one subgraph only:
   //
      node [color=red  fontcolor=red ]
      C
      D
   }

//
// The following node has only the
// shape attribute overridden:
//
   X
}
Github repository about-Graphviz, path: /elems/subgraph/attribute-context.dot

See also

Graphviz elements

Index