# How to draw a graph along with probabilty tables using TikZ package

I need help to draw a Directed Acyclic Graph of Bayesian Network along with probability of each node using TikZ package. Here is an example:

Table grid can be a full or partial as in above example.

-
You can put an entire tabular environment inside a tikz node, so you can integrate your tables in the tikz figure. It is all about node placement. Use positioning library. –  JLDiaz Feb 27 '13 at 23:33
This is very similar to Balanced Scorecard diagram. If you're not hooked on tikz, then the code could be adapted to produce the required output. –  Werner Feb 27 '13 at 23:43

I am in a good mood to provide you with a minimal working example (MWE) but in future questions, I advise you to provide one. (Summer break for teachers here :) See for instance: "Just do it for me" text building block

Here it is in tikz. You can do the rest for practice. See the pgfmanual. You can also type texdoc pgf in your terminal or command line.

Here are some explanations.

• Usually, node commands are done as follows: \node (<node name>) [<options>] {<text>};
• Edit: The positioning library enables you to specify how far the location of nodes/coordinates relative to other nodes/coordinates. Reference: Package PGF Math Error: Unknown operator o' or of'
• The arrows library allows you to use other types of arrows aside from the default of >.
• The shapes library allows usage of shapes like ellipse for nodes.

## The partial code

\documentclass[border=5, convert={density=150}]{standalone}

\usepackage{array}
\newcolumntype{C}{>{$}c<{$}}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows}
\tikzset{
events/.style={ellipse, draw, align=center},
}
\begin{document}
\begin{tikzpicture}[node distance=2cm, >=stealth']
\node [events] (cloudy) {Cloudy};
\node [events, below left = of cloudy] (sprinkler) {Sprinkler};
\node [events, below right = of cloudy] (rain) {Rain};
\node [events, below right = of sprinkler] (wetgrass) {WetGrass};

\draw [->] (cloudy) -- (sprinkler);
\draw [->] (cloudy) -- (rain);
\draw [->] (rain) -- (wetgrass);
\draw [->] (sprinkler) -- (wetgrass);

\node [above = of cloudy] {
\begin{tabular}{CC}
\mathrm{P(C=F)} & \mathrm{P(C=T)}\\
\hline
0.5 & 0.5\\
\end{tabular}
};

\node [right = of rain, anchor=west] {
\begin{tabular}{c|CC}
C & \mathrm{P(C=F)} & \mathrm{P(C=T)}\\
\hline
F & 0.8 & 0.2\\
T & 0.2 & 0.8\\
\end{tabular}
};

\end{tikzpicture}
\end{document}


## The output

-
Thanks a lot, you are a gentle man. –  user986789 Feb 28 '13 at 8:52
Your example even runs without positioning. The syntax for positioning is …=… of …, see Package PGF Math Error: Unknown operator o or of. The … of=… syntax is actually deprecated, see Difference between "right of=" and "right=of" in PGF/TikZ. –  Qrrbrbirlbel Feb 28 '13 at 13:27
@Qrrbrbirlbel I knew there was something off. That is why I had to drop by here early. Thanks a lot! –  hpesoj626 Feb 28 '13 at 21:27