1

I am working on a paper in LaTeX and I'm trying to insert a simple decision tree diagram using TikZ. However, I am not good with TikZ and I'm having two small problems with my tree.

enter image description here

This is my tree right now, and I am having trouble with it in two ways:

  1. I would like to get rid of the extra horizontal line before the top R=0.
  2. I would like for the nodes to be inside of circles.

Again, I'm not good with TikZ, and can't seem to get it to work. My code is below.

{
% 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]

%TODO: fix top node
\begin{figure}[h]
\centering
\begin{tikzpicture}[grow=right, sloped, scale=0.8]
\node[bag] {$L$}
    child {
        node[bag] {$D$}        
            child {
                node[bag] {$P$}
                    child {
                        node[bag] {$C$}
                            child {
                                node[end, label=right:
                                {$\mathbf{R=1}$}] {}
                                edge from parent
                                %node[above] {$E$}
                                node[below]  {$C=0$}
                            }
                            child {
                                node[end, label=right:
                                {$\mathbf{R=0}$}] {}
                                edge from parent
                                %node[above] {$E$}
                                node[below]  {$C=1$}
                            }
                        edge from parent
                        %node[above] {$E$}
                        node[below]  {$P=0$}
                    }
                    child {
                        node[end, label=right:
                        {$\mathbf{R=0}$}] {}
                        edge from parent
                        %node[above] {$E$}
                        node[below]  {$P=1$}
                    }
                edge from parent
                %node[above] {$W$}
                node[below]  {$D=0$}
            }
            child {
                node[end, label=right:
                    {$\mathbf{R=0}$}] {}
                edge from parent
                %node[above] {$E$}
                node[below]  {$D=1$}
            }
            edge from parent 
            %node[above] {$W$}
            node[below]  {$L=0$}
    }
    child {
           child {
            node[end, label=right:
            {$\mathbf{R=0}$}] {}
            edge from parent
            %node[above] {$E$}
            %node[below]  {$C=0$}
           }
        edge from parent         
            %node[above] {$B$}
            node[below]  {$L=1$}
    };
\end{tikzpicture}
\end{figure}
}

If anyone who is better at TikZ than I am could help me out with this, it would be greatly appreciated.

  • Thanks for the comment. I went ahead and used the forest package, and the results can be seen in my answer. I found that much easier to understand, especially after reading this very helpful answer. – i love fish Apr 29 '15 at 19:10