I have made a stacked and clustered diagram, based on this brilliant answer: https://tex.stackexchange.com/a/55559/93892. However, I would like to change the colors of the bars. The most important thing is I'd like to change from red and blue to shades of gray/black. It might be interesting having a distinction between every second column (to distinguish between Initial and Main), but this is not crucial.
I have tried a few approaches with no success. I suspect this should be quite easy, so if any of you immediately see how it's done some input would be highly appreciated.
\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\newcounter{groupcount}
\pgfplotsset{
draw group line/.style n args={5}{
after end axis/.append code={
\setcounter{groupcount}{0}
\pgfplotstableforeachcolumnelement{#1}\of\datatable\as\cell{%
\def\temp{#2}
\ifx\temp\cell
\ifnum\thegroupcount=0
\stepcounter{groupcount}
\pgfplotstablegetelem{\pgfplotstablerow}{X}\of\datatable
\coordinate [yshift=#4] (startgroup) at (axis cs:\pgfplotsretval,0);
\else
\pgfplotstablegetelem{\pgfplotstablerow}{X}\of\datatable
\coordinate [yshift=#4] (endgroup) at (axis cs:\pgfplotsretval,0);
\fi
\else
\ifnum\thegroupcount=1
\setcounter{groupcount}{0}
\draw [
shorten >=-#5,
shorten <=-#5
] (startgroup) -- node [anchor=base, yshift=0.5ex] {#3} (endgroup);
\fi
\fi
}
\ifnum\thegroupcount=1
\setcounter{groupcount}{0}
\draw [
shorten >=-#5,
shorten <=-#5
] (startgroup) -- node [anchor=base, yshift=0.5ex] {#3} (endgroup);
\fi
}
}
}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\pgfplotstableread{
X Md Ts Name Remaining Removed
1 Initial 30min Constraints 30182 5158
2 Initial 30min Variables 34018 86
4 Main 30min Constraints 3257 2787
5 Main 30min Variables 5615 373
8 Initial 15min Constraints 59924 9436
9 Initial 15min Variables 67406 172
11 Main 15min Constraints 7582 4100
12 Main 15min Variables 11027 841
15 Initial 5min Constraints 176321 29119
16 Initial 5min Variables 200985 516
18 Main 5min Constraints 20398 10696
19 Main 5min Variables 31350 2068
}\datatable
\begin{axis}[
scaled ticks=false,
tick label style={/pgf/number format/fixed},
axis lines*=left, ymajorgrids,
ymax = 220000,
width=12cm, height=15cm,
ymin=0,
ybar stacked,
bar width=11pt,
xtick=data,
xticklabels from table={\datatable}{Name},
xticklabel style={rotate=90,xshift=-7ex,anchor=mid east},
legend style={at={(0.04,0.93)},anchor=west},
draw group line={Ts}{30min}{30min}{-4ex}{4pt},
draw group line={Ts}{15min}{15min}{-4ex}{4pt},
draw group line={Ts}{5min}{5min}{-4ex}{4pt},
draw group line={Md}{Initial}{Initial}{-7ex}{4pt},
draw group line={Md}{Main}{Main}{-7ex}{4pt},
after end axis/.append code={
\path [anchor=base east, yshift=0.5ex]
(rel axis cs:0,0) node [yshift=-7ex] {Model}
(rel axis cs:0,0) node [yshift=-4ex] {Time slot size};
}]
\addplot table [x=X, y=Remaining] {\datatable}; \addlegendentry{Remaining}
\addplot table [x=X, y=Removed] {\datatable}; \addlegendentry{Removed}
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}