TikZ 決定木図 - 余分な線と円状のノードを削除しますか?

TikZ 決定木図 - 余分な線と円状のノードを削除しますか?

私は LaTeX で論文を作成しており、TikZ を使用して簡単な決定木図を挿入しようとしています。しかし、私は TikZ に詳しくなく、ツリーに 2 つの小さな問題があります。

ここに画像の説明を入力してください

これは現在私が管理しているツリーですが、2 つの点で問題があります。

  1. 上部の R=0 の前の余分な水平線を削除したいと思います。
  2. ノードを円の中に配置したいと思います。

繰り返しますが、私は TikZ に詳しくないので、うまく動作させることができません。私のコードは以下の通りです。

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

私よりも TikZ に詳しい方がいらっしゃいましたら、ご協力いただければ幸いです。

答え1

私は助けを借りてそれを理解しましたhttps://tex.stackexchange.com/a/240766/77231

これが私の新しい写真です:

木

そして私の新しいコード:

\documentclass[tikz]{standalone}
\usepackage{forest}
\begin{document}
\tikzset{
    decision/.style={circle, minimum height=10pt, minimum width=10pt, draw=black, fill=none, thick, inner sep=0pt},
    chance/.style={circle, minimum width=10pt, draw=black, fill=none, thick, inner sep=0pt},
  }
 \begin{forest}
    my label/.style={
      edge label={node[auto,sloped,pos=.75,anchor=south]{#1}}
    },
    for tree={
      grow=0,
      child anchor=west,
      anchor=west,
      text ragged,
      inner sep=1mm,
      edge={thick, draw=black},
      l sep+=15mm,
      s sep+=15mm,
      if n children=0{
        before typesetting nodes={
          label/.wrap pgfmath arg={right:#1}{content()},
          content={},
          chance,
        },
      }{},
      edge path={
        \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) |- (.child anchor)\forestoption{edge label};
      }
    }
    [, decision
      [, chance, my label={$L=0$}
        [, chance, my label={$D=0$}
          [, chance, my label={$P=0$}
            [{$\mathbf{R=1}$}, my label={$C=0$}
            ]
            [{$\mathbf{R=0}$}, my label={$C=1$}
            ]
          ]
          [{$\mathbf{R=0}$}, my label={$P=1$}
          ]
        ]
        [{$\mathbf{R=0}$}, my label={$D=1$}
        ]
      ]
      [{$\mathbf{R=0}$}, my label={$L=1$}
      ]
    ]
  \end{forest}
\end{document}

これはもっとすっきりして良いと思います。cfrさんの回答に再度感謝します。https://tex.stackexchange.com/a/240766/77231

関連情報