1

I am trying to make a vertical "reverse" decision tree inspired on this.

This is my trial:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,shadows}
\begin{document}
% Define block styles used later
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em, 
    text centered, minimum height=2.5em,drop shadow]
\tikzstyle{wa} = [sensor, text width=6em, fill=red!20, 
    minimum height=3em, rounded corners, drop shadow]
% Define distances for bordering
\def\blockdist{2.3}
\def\edgedist{2.5}
\begin{tikzpicture}
    \node (wa) [wa]  {NB Best};
    \path (wa.west)+(-3.2,1.5) node (asr1) [sensor] {$NB_1$};
    \path (wa.west)+(-3.2,0.5) node (asr2)[sensor] {$NB_2$};
    \path (wa.west)+(-3.2,-0.5) node (asr3)[sensor] {$NB_3$}; 
    \path (wa.west)+(-3.2,-1.5) node (asr4)[sensor] {$NB_4$};    
   
    \path (wa.east)+(\blockdist,0) node (vote) [sensor] {NB filtered};

    \path [draw, ->] (asr1.east) -- node [above] {} 
        (wa.155) ;
    \path [draw, ->] (asr2.east) -- node [above] {} 
        (wa.170);
    \path [draw, ->] (asr3.east) -- node [above] {} 
        (wa.190);
    \path [draw, ->] (asr4.east) -- node [above] {} 
        (wa.205);
    \path [draw, ->] (wa.east) -- node [above] {} 
        (vote.west);
\end{tikzpicture}
\end{document}

which produces:

enter image description here

When I try to use the same structure below this first tree, they overlap each other. And I don't know to fix it, and move on to the desired diagram:

enter image description here

Appreciate any help!

2

With the use of a scope and yshift. The idea is to change the minimum for each block, which for me is the text of the nodes, not even their names. Then shift it in height. I have not deleted anything, but commented what is not neccesary so you have a reference, as I did not change your code. I added the "Best model" node.

The image:

enter image description here

The code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,shadows,decorations.pathreplacing}
\begin{document}
% Define block styles used later
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em, 
    text centered, minimum height=2.5em,drop shadow]
\tikzstyle{wa} = [sensor, text width=6em, fill=red!20, 
    minimum height=3em, rounded corners, drop shadow]
% Define distances for bordering
\def\blockdist{2.3}
\def\edgedist{2.5}
\begin{tikzpicture}
    
    \node (best) [wa, align = center] at (4,0) {BEST \\ MODEL};
    
    \begin{scope}[yshift = 3cm]
        \node (wa) [wa]  {P};
        \draw[-latex] (wa.east) -- (best);
        %\path (wa.west)+(-3.2,1.5) node (asr1) [sensor] {$NB_1$};
        \path (wa.west)+(-3.2,0.5) node (asr2)[sensor] {$P$};
        %\path (wa.west)+(-3.2,-0.5) node (asr3)[sensor] {$NB_3$}; 
        %\path (wa.west)+(-3.2,-1.5) node (asr4)[sensor] {$NB_4$};    
        
        %\path (wa.east)+(\blockdist,0) node (vote) [sensor] {NB filtered};
        
        %\path [draw, ->] (asr1.east) -- node [above] {} 
        %(wa.155) ;
        \path [draw, ->] (asr2.east) -- node [above] {} 
        (wa.170);
        %\path [draw, ->] (asr3.east) -- node [above] {} 
        %(wa.190);
        %\path [draw, ->] (asr4.east) -- node [above] {} 
        %(wa.205);
        %\path [draw, ->] (wa.east) -- node [above] {} 
        %(vote.west)
    \end{scope}
    
    \begin{scope}[yshift = 0cm]
       \node (wa) [wa]  {NB Best};
       \draw[-latex] (wa.east) -- (best);
        \path (wa.west)+(-3.2,1.5) node (asr1) [sensor] {$NB_1$};
        \path (wa.west)+(-3.2,0.5) node (asr2)[sensor] {$NB_2$};
        \path (wa.west)+(-3.2,-0.5) node (asr3)[sensor] {$NB_3$}; 
        \path (wa.west)+(-3.2,-1.5) node (asr4)[sensor] {$NB_4$};    
        
        %\path (wa.east)+(\blockdist,0) node (vote) [sensor] {NB filtered};
        
        \path [draw, ->] (asr1.east) -- node [above] {} 
        (wa.155) ;
        \path [draw, ->] (asr2.east) -- node [above] {} 
        (wa.170);
        \path [draw, ->] (asr3.east) -- node [above] {} 
        (wa.190);
        \path [draw, ->] (asr4.east) -- node [above] {} 
        (wa.205);
        %\path [draw, ->] (wa.east) -- node [above] {} 
        %(vote.west);
    \end{scope}

    \begin{scope}[yshift = -5cm]
        \node (wa) [wa]  {CMP Best};
        \draw[-latex] (wa.east) -- (best);
        \path (wa.west)+(-3.2,1.5) node (asr1) [sensor] {$CMP_1$};
        \path (wa.west)+(-3.2,0.5) node (asr2)[sensor] {$CMP_2$};
        \path (wa.west)+(-3.2,-0.5) node (asr3)[sensor] {$CMP_3$}; 
        \path (wa.west)+(-3.2,-1.5) node (asr4)[sensor] {$CMP_4$};    
        
        %\path (wa.east)+(\blockdist,0) node (vote) [sensor] {CMP filtered};
        
        \path [draw, ->] (asr1.east) -- node [above] {} 
        (wa.155) ;
        \path [draw, ->] (asr2.east) -- node [above] {} 
        (wa.170);
        \path [draw, ->] (asr3.east) -- node [above] {} 
        (wa.190);
        \path [draw, ->] (asr4.east) -- node [above] {} 
        (wa.205);
        %\path [draw, ->] (wa.east) -- node [above] {} 
        %(vote.west);
    \end{scope}
    
    \draw [decorate,decoration={brace,amplitude=5pt,mirror,raise=4ex}]
    (wa.south) --++(4,0) node[midway,yshift=-5em, align = center]{Linear \\ Prediction \\  Filter};
    
\end{tikzpicture}
\end{document}
5
  • Sorry to bother. Is there a way to include a legend in on it? I tried with \matrix [draw,above right] at (current bounding box.north east) { \node [label=1 Full model] {}; \\ \node [label=2 Fixed variance] {}; \\ \node [label=3 Comum variance] {}; \\ \node [label=4 Fixed dispersion] {}; \\ };, but I obtained a not beautiful legend. I just want to point the meaning of 1, 2, 3 and 4. It could be located in another position too Mar 17 at 19:05
  • Hmm I am quite bad with these kind of labes and usually take a cavernman approach to them. Mostly, a multiline node (hehe). I did not test it, but probably something like this: \node[align=left, anchor=south] (textNode) at (best.north) {1 - Full model // 2 - Fixed variance // 3 - Comum variance // 4 - Fixed dispersion};. This allows you to do some easy formatting on the node. Let me know if it works and you like it!
    – Jes
    Mar 17 at 19:38
  • Thank you Jes!! It work for me! I had to change // to \\ and (best.north) to (4,2) to the legend be placed in a further top right position Mar 17 at 20:29
  • 1
    Oops sorry, I wrote this from my phone so I couldn't check it haha. Glad to be of help!
    – Jes
    Mar 17 at 20:53
  • 1
    I imagined that hehe thank you for quick reply Mar 17 at 20:56
2

Similar solution to Jes one, but with forest

\documentclass[border=2mm]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta, shadows, decorations.pathreplacing}

\begin{document}  
\begin{forest}
    for tree={grow=west, draw, 
         drop shadow, text centered,
        edge=Stealth-, child anchor=east, l sep=1cm,
        },
    where level=2{fill=blue!30, sharp corners, text width=5em, minimum height=2.5em, math content}%
    {text width=6em, minimum height=3em, rounded corners, fill=red!30,}
[BEST\\ MODEL, align=center, name=root
    [P
        [P]]
    [NB Best 
        [NB_1]
        [NB_2]
        [NB_3]
        [NB_4]]
    [CMP Best, name=CMP
        [CMP_1]
        [CMP_2]
        [CMP_3]
        [CMP_4]]]
    \draw [decorate,decoration={brace,amplitude=5pt,mirror,raise=4ex}]
    (CMP.south) --(CMP.south-|root) node[midway,yshift=-5em, align = center]{Linear \\ Prediction \\  Filter};
\end{forest}
\end{document}

enter image description here

4
  • Ooh clever! I am currently trying to learn foests and mindmaps so seeing these kind of possibikitirs are very helpful!
    – Jes
    Mar 17 at 19:12
  • Sorry to bother. Is there a way to include a legend in on it? I tried with \matrix [draw,above right] at (current bounding box.north east) { \node [label=1 Full model] {}; \\ \node [label=2 Fixed variance] {}; \\ \node [label=3 Comum variance] {}; \\ \node [label=4 Fixed dispersion] {}; \\ };, but I obtained a not beautiful legend. I just want to point the meaning of 1, 2, 3 and 4. It could be located in another position too Mar 17 at 20:05
  • 1
    @GuilhermeParreira the solution provided by Jes can be also applied here. If you want a particular node as reference, add the name to it.
    – Ignasi
    Mar 18 at 7:54
  • Thank you Ignasi!! Mar 18 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.