[Tex/LaTex] How to draw this graph with TikZ or forest

forestgraphstikz-pgf

I want to replicate the structure of the picture below. I don't want to replicate the appearance.

enter image description here

This LaTeX code

\documentclass[tikz,convert={size=640},multi]{standalone}
\usetikzlibrary{graphs,positioning}
\usepackage{forest}
\forestset{
  default preamble={
    grow=west,
    for tree={
      parent anchor=children,
      child anchor=east,
      anchor=east,
      draw
    }
  }
}
\begin{document}
\begin{forest}
  [Acceleration
  [Map] [Destination] [Vector] [Location]
  [{Kind(Street signs, cars, people,...)},name=kind] [Distance,name=distance]]
  \graph {
    Pixel -- Line -- Shape[left=of kind.west] -- {(distance.west),(kind.west)}
  };
\end{forest}
\begin{tikzpicture}
  \graph[grow left,left anchor=west,right anchor=east] {
    Acceleration[anchor=west] --
    {Map[anchor=east], Destination[anchor=east], Vector[anchor=east],
      Location[anchor=east],
      {{Kind/{Kind(Street signs, cars, people,...)}[anchor=east],
      Distance[anchor=east]} -- Shape[anchor=east]}}
  };
\end{tikzpicture}
\end{document}
%%% Local Variables:
%%% TeX-command-extra-options: "-shell-escape"
%%% mode: latex
%%% TeX-master: t
%%% End:

renders the two pictures below.

enter image description here

enter image description here

What did I do wrong? How can I fix the pictures?

Best Answer

It isn't entirely clear what you mean by 'structure'. Normally, for a graph or tree, I'd understand this to mean the way in which the nodes are connected to each other and not the distance and direction of one node relative to another. But it seems you mean the latter as well, although whether this is really it is another matter.

If so, I take it you want something like this:

structural replication

This is not hard to do in forest. It is just a bit fiddly:

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\forestset{
  default preamble={
    for tree={
      grow=west,
      parent anchor=children,
      child anchor=parent,
      anchor=east,
      draw,
      minimum height=4ex
    }
  }
}
\begin{document}
\begin{forest}
  [Acceleration
    [Map]
    [Destination]
    [Vector]
    [Location]
    [{Kind(Street signs, cars, people,...)}, name=kind, tikz+={%
      \draw [\forestoption{edge}] (.parent anchor) -- (shape.child anchor);
    }
    ]
    [, phantom
    [Shape, before computing xy={%
      l+/.wrap pgfmath arg={#1}{width(content("kind"))},
    }, name=shape
        [Line
          [Pixel]
        ]
      ]
    ]
    [Distance, before drawing tree={%
      x-/.wrap pgfmath arg={#1}{width(content("kind"))-width(content())}
    }, edge path'={%
      (!u.parent anchor) -- (kind.child anchor |- .child anchor) -- (.child anchor)
    }, tikz+={%
      \draw [\forestoption{edge}] (.parent anchor) -- (shape.child anchor);
    }
    ]
  ]
\end{forest}
\end{document}

EDIT

I have no idea what 'vertical space' you ask in the comments to get rid of. The following code sacrifices structural replication for the sake of what may or may not be the desired appearance.

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\forestset{
  default preamble={
    for tree={
      grow=west,
      parent anchor=children,
      child anchor=parent,
      anchor=east,
      draw,
      minimum height=4ex
    }
  }
}
\begin{document}
\begin{forest}
  [Acceleration
    [Map]
    [Destination]
    [Vector]
    [Location]
    [{Kind(Street signs, cars, people,...)}, name=kind
      [Shape, before computing xy={%
        s/.wrap pgfmath arg={#1}{(-s("!u")+s("!un"))/2},
      }, name=shape
        [Line
          [Pixel]
        ]
      ]
    ]
    [Distance, before drawing tree={%
      x-/.wrap pgfmath arg={#1}{width(content("kind"))-width(content())}
    }, edge path'={%
      (!u.parent anchor) -- (kind.child anchor |- .child anchor) -- (.child anchor)
    }, tikz+={%
      \draw [\forestoption{edge}] (.parent anchor) -- (shape.child anchor);
    }
    ]
  ]
\end{forest}
\end{document}

modified fiddling

Related Question