# Hierarchical tick-labels in PGF plot

I'm looking for a way to create hierarchical tick-labels in tikz/pdfplots - like in this example picture:

The 1st three groups describe the results of experiment A, with parameters 0, 4 and 8, the 2nd three groups do the same for experiment B, and so on.

However, I have no idea how to achieve this, and so far couldn't find any info online. Does anyone have a hint or solution for this problem? Many thanks for reading this!

Here is my code so far, where I didn't come up with a better solution than writing the parameter in parentheses and repeating the name of the experiment over and over again...

\documentclass[preview]{standalone}

\usepackage{pgfplots,pgfplotstable} % plots
\tikzset{every picture/.style={/utils/exec={\sffamily}}} % font for plots
\tikzset{every picture/.style={font=\small}} % font size for plots
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
width=12cm,
height=8cm,
ymax=93,
ymin=0,
ybar,
bar width=4pt,
symbolic x coords={A (0), A (4), A (8), B (0), B (4), B (8), C (0), C (4), C (8)},
xtick=data,
x tick label style={rotate=45,anchor=east}]

(A (0),61.682)
(A (4),63.104)
(A (8),60.82)

(B (0),65.454)
(B (4),65.396)
(B (8),63.69)

(C (0),77.73)
(C (4),75.756)
(C (8),70.29)};

(A (0),35.632)
(A (4),34.65)
(A (8),36.76)

(B (0),32.596)
(B (4),32.47)
(B (8),34.14)

(C (0),21.58)
(C (4),23.364)
(C (8),28.87)};

\end{axis}
\end{tikzpicture}

\end{document}


To get the right xticks, you can combine xtick and xticklabels. After that, nodes can be used to position the group titles A, B and C. For this, clipping must be switched off.

\documentclass{standalone}

\usepackage{pgfplots,pgfplotstable} % plots
\tikzset{every picture/.style={/utils/exec={\sffamily}}} % font for plots
\tikzset{every picture/.style={font=\small}} % font size for plots
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=12cm,
height=8cm,
ymax=93,
ymin=0,
ybar,
bar width=8pt,
% x ticks explicitly formatted
xtick={1,2,3,5,6,7,9,10,11},
xticklabels={$0$,$4$,$8$,$0$,$4$,$8$,$0$,$4$,$8$},
% turn of clipping
clip=false
]

coordinates {
(1,61.682)
(2,63.104)
(3,60.82)

(5,65.454)
(6,65.396)
(7,63.69)

(9,77.73)
(10,75.756)
(11,70.29)
};

coordinates {
(1,35.632)
(2,34.65)
(3,36.76)

(5,32.596)
(6,32.47)
(7,34.14)

(9,21.58)
(10,23.364)
(11,28.87)
};

\node[font=\bfseries] at (xticklabel cs:.1675,10pt) {A};
\node[font=\bfseries] at (xticklabel cs:.5000,10pt) {B};
\node[font=\bfseries] at (xticklabel cs:.8325,10pt) {C};
\end{axis}
\end{tikzpicture}
\end{document}