causal_networkx.graphs.dag.DAG.to_dot_graph#
- DAG.to_dot_graph(to_dagitty=False)#
Convert to ‘dot’ graph representation as a string.
The DOT language for graphviz is what is commonly used in R’s
dagitty
package. This is a string representation of the graph. However, this converts to a string format that is not 100% representative of DOT [1]. See Notes for more information.- Parameters:
to_dagitty : bool
Whether to conform to the Dagitty format, where the string begins with
dag {
instead ofstrict digraph {
.- Returns:
dot_graph :
str
A string representation in DOT format for the graph.
Notes
The output of this function can be immediately plugged into the dagitty online portal for drawing a graph.
For example, if we have a mixed edge graph, with directed and bidirected arrows (i.e. a causal DAG). Specifically, if we had
0 -> 1
with a latent confounder, we would get the following output:strict digraph { 0; 1; 0 -> 1; 0 <-> 1; }
To represent for example a bidirected edge,
A <-> B
, the DOT format would make you useA -> B [dir=both]
, but this is not as intuitive.A <-> B
also complies with dagitty and other approaches to drawing graphs in Python/R.References