2

In order to show the difference between three measurements against a single one, I need to combine a regular bar plot and with a stacked one. However, once I use a stacked bar plot, the single datum is shifted:

Imgur

This is what produced the plot:

\begin{tikzpicture}
\begin{axis}[
    xbar stacked,
    xmin=0,
  ]

  \addplot coordinates {
    ({0.394240+1.067584}, 0)
    ({0.614592+1.247520}, 1)
    ({1.862848+1.615360}, 2)
    ({4.025184+2.461248}, 3)
  };

  \addplot coordinates {
    ({0.333824+0.553664}, 0)
    ({0.602816+1.236160}, 1)
    ({1.719200+0.600512}, 2)
    ({3.526432+1.282208}, 3)
  };

  \addplot coordinates {
    ({0.334912+0.522688}, 0)
    ({0.642980+0.701760}, 1)
    ({1.873760+0.997440}, 2)
    ({3.856416+1.302432}, 3)
  };

  \addplot coordinates {
    (0.630336, 0.5)
    (1.925728, 1.5)
    (6.348640, 2.5)
    (15.193056, 3.5)
  };
\end{axis}
\end{tikzpicture}

Is it possible to shift the orange bar back to 0?

matthias
  • 291

1 Answers1

1

This is one possible solution. Since a single bar is an xbar without being stacked. So this solution proposes the axis environment to be used twice, one for xbar stacked and one for xbar. The final result has a group of floating black bars, which are for demonstration purpose. Simply remove the addplot command indicated by arrow <--- can get rid of them.

enter image description here

Code

\documentclass[border=10pt]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xbar stacked,
    xmin=0,xmax=40, ymax=4
  ]
  \addplot coordinates {
    ({0.394240+1.067584}, 0)
    ({0.614592+1.247520}, 1)
    ({1.862848+1.615360}, 2)
    ({4.025184+2.461248}, 3)
  };

  \addplot coordinates {
    ({0.333824+0.553664}, 0)
    ({0.602816+1.236160}, 1)
    ({1.719200+0.600512}, 2)
    ({3.526432+1.282208}, 3)
  };

  \addplot coordinates {
    ({0.334912+0.522688}, 0)
    ({0.642980+0.701760}, 1)
    ({1.873760+0.997440}, 2)
    ({3.856416+1.302432}, 3)
  };
%   Remove  this plot will remove the black bar
  \addplot coordinates { %<---
    (0.630336, 0.5)      %
    (1.925728, 1.5)      %
    (6.348640, 2.5)      %
    (15.193056, 3.5) };  %<---
\end{axis}

\begin{axis}[
    xbar, 
    axis y line=none,
    xmin=0,xmax=40, ymax=4,
]
  \addplot[fill=orange]  coordinates {
    (0,0)
    (0.630336, 0.5) 
    (1.925728, 1.5)
    (6.348640, 2.5)
    (15.193056, 3.5)};
\end{axis}
\end{tikzpicture}
\end{document}
Jesse
  • 29,686