Posted on August 8, 2013 @ 01:56:00 AM by Paul Meagher
I introduced the Graphviz program in my last blog. In today's blog I want to go a little deeper into the DOT language to show how you can achieve three useful effects using the DOT language. The three effects are:
- Change the overall layout of the graph. Instead of starting our decision tree from the top, I would prefer to start it from the left side of the canvas and expand it towards the right side of the canvas (i.e., left-to-right reading order). I can do this by adding the command
rankdir=LR; to my dot file.
- Would be nice to show probability values on links going into event nodes. For example, the probability of high rain fall this season. We do this by adding a bracket next to link commands and specifying the value for the "label" attribute (e.g.,
Action -> HighRainFall[label="0.6"];).
- If you are trying to highlight a path through a decision tree, then there are ways to highlight a path in graphviz. One way would be to thicken the line and add red coloration to each link in the path (e.g.,
Action -> LowRainFall[label="0.4",color=red,penwidth=3.0]; ).
If we put all these elements together in one dot program file, it would look like this:
Action -> LowRainFall[label="0.4",color=red,penwidth=3.0];
Action -> HighRainFall[label="0.6"];
If we load this dot file into the graphviz program "dot", it will generate this graph:
What we have here is a fragment of a graph. A fragment like this might appear in your decision tree leading from an action node to an event node. This is how we can get probabilities to appear on our graphical representations of a decision problem. Also, I like to orient the tree from left-to-right because if you have a large branchy tree it can more easily be printed off whereas top-to-bottom trees are hard to print off and involve alot of horizontal scrolling to view. Finally, when you make a decision to pursue a particular course of action, you can highlight that course of action graphically with a thick red pen effect.