A simple example of a probability tree diagram.
Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the
LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.
En français: TeXnique.fr.
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\pagestyle{empty}
% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]
% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]
% The sloped option gives rotated edge labels. Personally
% I find sloped labels a bit difficult to read. Remove the sloped options
% to get horizontal labels.
\begin{tikzpicture}[grow=right, sloped]
\node[bag] {Bag 1 $4W, 3B$}
child {
node[bag] {Bag 2 $4W, 5B$}
child {
node[end, label=right:
{$P(W_1\cap W_2)=\frac{4}{7}\cdot\frac{4}{9}$}] {}
edge from parent
node[above] {$W$}
node[below] {$\frac{4}{9}$}
}
child {
node[end, label=right:
{$P(W_1\cap B_2)=\frac{4}{7}\cdot\frac{5}{9}$}] {}
edge from parent
node[above] {$B$}
node[below] {$\frac{5}{9}$}
}
edge from parent
node[above] {$W$}
node[below] {$\frac{4}{7}$}
}
child {
node[bag] {Bag 2 $3W, 6B$}
child {
node[end, label=right:
{$P(B_1\cap W_2)=\frac{3}{7}\cdot\frac{3}{9}$}] {}
edge from parent
node[above] {$B$}
node[below] {$\frac{3}{9}$}
}
child {
node[end, label=right:
{$P(B_1\cap B_2)=\frac{3}{7}\cdot\frac{6}{9}$}] {}
edge from parent
node[above] {$W$}
node[below] {$\frac{6}{9}$}
}
edge from parent
node[above] {$B$}
node[below] {$\frac{3}{7}$}
};
\end{tikzpicture}
\end{document}
Comments
How can I insert arrows instead of dots at the end of the line? Thanks!
thanks, really useful
Very helpful. Thanks! :)
Thank you!
I think you inverted the first two probabilities
Adding comments is currently not enabled.