I'm trying to make a bar plot where i always have one single bar paired against multiple bars. Two problems arise -- first, the first bar is assumed to have 6 other bar buddies and gets pushed to the left. I am aware that this has been answered here, but there's more. The second problem is, assuming that solution (2nd MWE) I get an absurd ammount of wasted white space between groups. Any ideas on how to achieve even spacing between bar groups and plot edges? Dirty hacks and manual approaches are fine if needed be.
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
width=12cm,
xmin=0,xmax=2,
enlarge x limits=0.3,
]
\addplot coordinates {
(0,2.5) };
\addplot coordinates {
(1,5) (2,7) };
\addplot coordinates {
(1,4) (2,10) };
\addplot coordinates {
(1,5) (2,8) };
\addplot coordinates {
(1,2) (2,6) };
\addplot coordinates {
(1,8) (2,10) };
\addplot coordinates {
(1,7) (2,4) };
\end{axis}
\end{tikzpicture}
\end{document}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{
% #1: index in the group(0,1,2,...)
% #2: number of plots of that group
bar group size/.style 2 args={
/pgf/bar shift={%
% total width = n*w + (n-1)*skip
% -> subtract half for centering
-0.5*(#2*\pgfplotbarwidth + (#2-1)*\pgfkeysvalueof{/pgfplots/bar group skip}) +
% the '0.5*w' is for centering
(.5+#1)*\pgfplotbarwidth + #1*\pgfkeysvalueof{/pgfplots/bar group skip}},%
},
bar group skip/.initial=0pt,
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
plot1/.style={fill=red!20},
plot2/.style={fill=blue!20},
ybar,
width=12cm,
xmin=0,xmax=2,
enlarge x limits=0.2,
]
\addplot [bar group size={5}{6}] coordinates {
(0,2.5) };
\addplot [plot1,bar group size={0}{6}] coordinates {
(1,5) (2,7) };
\addplot [plot2,bar group size={1}{6}] coordinates {
(1,4) (2,10) };
\addplot [plot1,bar group size={2}{6}] coordinates {
(1,5) (2,8) };
\addplot [plot2,bar group size={3}{6}] coordinates {
(1,2) (2,6) };
\addplot [plot1,bar group size={4}{6}] coordinates {
(1,8) (2,10) };
\addplot [plot2,bar group size={5}{6}] coordinates {
(1,7) (2,4) };
\end{axis}
\end{tikzpicture}
\end{document}
