I want to make a Legend/Key in GraphViz. I make one successfully, but then how can I position it at the bottom right corner of the graph? I try using pos
but it doesn't work (it seems like it's only applicable in neato). This is my test code:
digraph {
rankdir="LR";
a -> b -> c -> a
subgraph cluster_Legend {
label = "Legend";
rank=same;
e -> f
}
Normally, if the legend is actually an HTML table embeded in the lable, one can use labelloc="b" labeljust="r"
. However, in my case the items to be explained in the legends are edges, not nodes, so my legend needs to consist two tables. Therefore using labelloc
only moves the texts in the legend box, not the legend box itself.
My legend can be coded in two forms: table and non-table
Table version
digraph {
subgraph clusterLegend {
rank = sink;
label = "Legend";
fontsize = 20
node [ color="white" ]
{rank=same; key, key2}
key [ label=<<table border="0" cellpadding="2" cellspacing="0" cellborder="0">
<tr><td align="right" port="i1">A</td></tr>
<tr><td align="right" port="i2">A</td></tr>
</table>> ]
key2 [ label=<<table border="0" cellpadding="2" cellspacing="0" cellborder="0">
<tr><td align="left" port="i1">B</td><td> The reason for A is B</td></tr>
<tr><td align="left" port="i2">B</td><td> The solution for A is B</td></tr>
</table>>]
key:i1 -> key2:i1
key:i2 -> key2:i2 [ arrowhead="odiamond" style=dashed ]
}
}
Non-table version
{rank=same; a1, b1 }
{rank=same; a2, b2 }
a1 [label="A"]
a2 [label="A"]
b1 [label="B The reason for A is B"]
b2 [label="B The solution for A is B"]
a1 -> b1 [ minlen=4 ]
a2 -> b2 [ minlen=4 arrowhead="odiamond" style=dashed ]
I think if we are to use labelloc
and labeljust
, then we need to figure out how to put arrows as items of table. Is there a way to do so?
This is my real graph.
See more: Placing Graphviz nodes in fixed positions / Magnus Jacobsson / Observable