# Bar chart using pgfplots with both positive and negative bars

I am trying to create a bar chart with both positive and negative stacked bars. However, my negative bar doesn't appear/it is hidden behind the positive bars. How should I change the settings to make the positive bars stacked and make the negative bar appear below them?

Here's a MWE:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar stacked,xtick=\empty,ytick=\empty]
\legend{Income1,Income2,Investment}
\end{axis}
\end{tikzpicture}
\end{document}


Which generates:

• @ChristianFeuersänger may I ping you to this post? Looks a bit odd. I hope I did not miss something. Thank you. Dec 15 '14 at 16:18

I would report that to the maintainers. Looks really strange. If you do not stack them, one gets the correct result.

% arara: pdflatex

\documentclass[tikz,border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,xtick=\empty,ytick=\empty,legend cell align=left, legend style={legend pos=north west}]
\legend{Income1,Income2,Investment}
\end{axis}
\end{tikzpicture}
\end{document}


• I'm glad you understand the question. If we could stack the first two bars and then plot the negative bar in the same axis but without appending it to the existing bars, the problem would be solved
– user49901
Dec 15 '14 at 16:34

I solved it by using groupplots and some manipulations.

Code:

\documentclass[]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size= 1 by 2},height=5cm,width=6.4cm,xtick=\empty]%[ybar stacked,xtick=\empty,]%ytick=\empty]
\nextgroupplot[ybar stacked,xtick=\empty,ymin=0,ymax=3,legend style = {at={(1.05, 0.5)}, anchor = west, legend columns =1, draw=none, area legend},  ymajorgrids = true,]%ytick=\empty]
coordinates {(0,1) (.5,1.5) (1,2)};