# How can I get titles on the top of grouped bars?

I have a bar plot with grouped bars. Each group should contain the total sum on top of the group.

Example:

My example has two problems:

• The x-position is estimated
• The y-psition (height) depends on the 2nd bar

How can I get the sums to their correct positions?

The example is created with this code:

\documentclass[border=5mm] {standalone}
\usepackage{pgfplots, pgfplotstable}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
title={Test},
ybar, ymin=3,
bar width=5mm,
enlarge y limits ={value=0.3,upper},
symbolic x coords={a,b,c,d},
xtick=data,
nodes near coords,
nodes near coords align={anchor=north},%Move values in bar anchor=mid
]
%Active
({a},15) [xa]
({b},25)
({c},35)
({d},55)};
%Inactive
({a},60)
({b},50)
({c},40)
({d},30)}
[yshift=5mm]
node[pos=0] {a: 75}
node[pos=.25] {b: 75}
node[pos=.5] {c: 75}
node[pos=1] {d: 45};
\end{axis}
\end{tikzpicture}
\end{document}

Remarks:

\documentclass[border=5mm] {standalone}
\usepackage{pgfplots, pgfplotstable}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
title={Test},
ybar, ymin=3,  ymax=80,
bar width=5mm,
symbolic x coords={a,b,c,d},
xtick=data,
nodes near coords,
nodes near coords align={anchor=north},%Move values in bar anchor=mid
]
%Active
({a},15) [xa]
({b},25)
({c},35)
({d},55)};
%Inactive
({a},60)
({b},50)
({c},40)
({d},30)};
\node at (axis cs:a,65) {a: 75};
\node at (axis cs:b,55) {b: 75};
\node at (axis cs:c,45) {c: 75};
\node at (axis cs:d,60) {d: 85};
\end{axis}
\end{tikzpicture}
\end{document}

• The axis cs defines the x-coordinate - great! Did I understand correct: for the height you take the biggest value + 5?
– knut
Commented Aug 24, 2013 at 0:01
• @knut yes, you understand correct. Then you can choose the value you prefer for the height.
– Red
Commented Aug 24, 2013 at 8:19