Example: Sub series in stacked bar plot

Published 2014-03-28 | Author: Elke Schubert

Two series will be shown in a bar plot. Additionally, they contain sub series, which we would like to plot in the same diagram. So we just need a 2D plot. We will shift the series to achieve that.

Download as: [PDF] [TEX]  •  [Open in Overleaf]

Sub series in stacked bar plot

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.

\pgfplotsset{compat = 1.8}
  \pgfplotsset{ybar stacked, ymin=0, ymax=100, xmin=0.5, xmax=2.5, xtick=data}
  \begin{axis}[bar shift=-8pt,
    legend pos = outer north east, legend style = {name = serieA}]
    \addplot [fill=xcolorA] table [x index = 0, y index = 1] {serieA.dat};
    \addplot [fill=ycolorA] table [x index = 0, y index = 2] {serieA.dat};
    \legend{x (Serie A), y (Serie A)}
  \begin{axis}[bar shift = 8pt,
    legend style = {at = {([yshift = -1mm]serieA.south west)},
      anchor = north west}]
    \addplot [fill = xcolorB] table [x index = 0, y index = 1] {serieB.dat};
    \addplot [fill = ycolorB] table [x index = 0, y index = 2] {serieB.dat};
    \legend{x (Serie B), y (Serie B)}


Adding comments is currently not enabled.