2

How do I center the coordinates in their bars vertically? This shows horizontally in ybar

\documentclass[tikz,border=12pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{compat=newest}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
ybar stacked,
legend style={at={(0.5,-0.50)},
anchor=north,legend columns=-1},
ylabel={Probability},
symbolic x coords={{Direct Care}, Housekeeping, Mealtimes, {Medication Round},
Miscellaneous,{Personal Care}},
xtick=data,
ymax=1,
x tick label style={rotate=45,anchor=east},
every node near coord/.style={
      check for zero/.code={
        \pgfkeys{/pgf/fpu=true}
        \pgfmathparse{\pgfplotspointmeta-.1}
        \pgfmathfloatifflags{\pgfmathresult}{-}{
           \pgfkeys{/tikz/coordinate}
        }{}
        \pgfkeys{/pgf/fpu=false}
      }, check for zero, yshift=3, font=\scriptsize},
    nodes near coords={\pgfmathprintnumber[precision=2]{\pgfplotspointmeta}},
    nodes near coords align=center
]
\addplot+[ybar] plot coordinates {({Direct Care},0.258883249)
({Housekeeping},0.176470588)
({Mealtimes},0.19047619)
({Medication Round},0.207207207)
({Miscellaneous},0.222222222)
({Personal Care},0.615384615)
};
\addplot+[ybar] plot coordinates {({Direct Care},0.015228426)
({Housekeeping},0.235294118)
({Mealtimes},0)
({Medication Round},0.027027027)
({Miscellaneous},0)
({Personal Care},0.153846154)
};
\addplot+[ybar] plot coordinates {({Direct Care},0.152284264)
({Housekeeping},0.058823529)
({Mealtimes},0.333333333)
({Medication Round},0.351351351)
({Miscellaneous},0.180555556)
({Personal Care},0.153846154)
};
\legend{{Handwash only},{Gloves only},{Alcohol rub only}}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

2
  • Shouldn't the solution in the linked question apply to you as well? You're using ybar just like the linked question – Jake Apr 3 '13 at 19:49
  • Perhaps but I can't seem to implement it satisfactorily. – HCAI Apr 4 '13 at 15:46