Using \pgfplots
, I have a bar chart that looks like this:
Instead, I would like to have something like this, so that I have two groups ("Freie Wiedergabe Tag 1" and "Freie Wiedergabe Tag 2") in 2 categories ("Erinnert" and "Nicht erinnert") and with two bars ("neutral" and "negativ") each. I have no idea how to do this:
My MWE is here:
\documentclass{apa6}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=1.6,transform shape]
\begin{axis}[
ybar,
enlargelimits=0.15,
legend style={at={(0.5,-0.25)},
anchor=north,legend columns=-1},
ylabel={Anteil},
symbolic x coords={Freie Wiedergabe Tag 1,Freie Wiedergabe Tag 2,Treffer,Falscher Alarm},
xtick=data,
xticklabel style={text width=1.5cm,
font=\tiny,
align=center
},
]
%neutral
\addplot[blue,fill=blue!30!white,error bars/.cd,y dir=both,y explicit,]
coordinates{(Treffer,0.8560) +-(0.01503,0.01503) (Falscher Alarm,0.1390) +-(0.01737,0.01737)(Freie Wiedergabe Tag 1,0.1481) +-(0.01067,0.01067) (Freie Wiedergabe Tag 2,0.1119) +-(0.00922,0.00922) };
%negativ
\addplot[red,fill=red!30!white,error bars/.cd,y dir=both,y explicit,]
coordinates {(Treffer,0.9365) +- (0.00587,0.00587)(Falscher Alarm,0.1435) +- (0.01737,0.01737)(Freie Wiedergabe Tag 1,0.3247) +-(0.01695,0.01695) (Freie Wiedergabe Tag 2,0.2556) +-(0.01524,0.01524)
};
\legend{neutral,negativ}
\end{axis}
\end{tikzpicture}
\caption{Unterschrift}
\label{GedaechtnisBilder}
\end{figure}
\end{document}
Best Answer
The data points are probably not in the correct place, but apart from that one way of achieving that is shown below. I've changed the coordinates to numerical x-values (1,2,3,4) instead of symbolic coordinates, and set
xticklabels={Erinnert,Nicht erinnert,Erinnert,Nicht erinnert}
. So the four data points in each\addplot
should correspond to those categories, the first two for the first day, the last two for the second day.Then I've added two
extra x ticks={1.5,3.5}
(midway between the two groups of bars), withextra x tick labels={Freie Wiedergabe Tag 1,Freie Wiedergabe Tag 2}
. Some vertical shifting of the ticklabels is done.