1

enter image description hereI'm new to LaTeX. Can anyone please help in changing the colour of stacked bars? Here is the code for the plot:

\pgfplotstableread[col sep=comma,header=false]{
All,192,37
completed,61,11
dropped,64,17
in study,47,3
changed,26,6
}\data

\pgfplotstablecreatecol[
create col/expr={
    \thisrow{1} + \thisrow{2}
}
]{sum}{\data}

\pgfplotsset{
percentage plot/.style={
        point meta=explicit,
every node near coord/.append style={
    xshift=17pt,
    yshift=-1.15pt,
    anchor=east,
%       font=\footnotesize,
    color=black,
            align=center,
        text width=1cm,
    },
    nodes near coords={
        \pgfmathtruncatemacro\iszero{\originalvalue==0}
        \ifnum\iszero=0
%       \pgfmathprintnumber{\originalvalue}$\,\%$\\
    \pgfmathprintnumber[fixed zerofill,precision=0]{\pgfplotspointmeta}
        \fi},
 nodes near coords align={vertical},
        yticklabel=\pgfmathprintnumber{\tick}\,$\%$,
        ymin=0,
        ymax=100,
 %        enlarge y limits={upper,value=0.1},
    visualization depends on={y \as \originalvalue}
 },
 percentage series/.style={
    table/y expr=(\thisrow{#1}/\thisrow{sum}*100),table/meta=#1
 }
 }

 \begin{tikzpicture}
 \begin{axis}[
    ybar stacked,
 %       axis on top,
 height=8cm,
 %    width=10cm,
    percentage plot,
 %   axis y discontinuity=crunch,
 bar width=0.85cm,
 symbolic x coords={All,completed,dropped,in study,changed},
    xtick=data,
x tick label style={rotate=45, anchor=east, xshift=-1.5mm, yshift=-2mm},
%   ylabel={\#a},
%    enlargelimits=0.15,
 legend style={
    at={(0.5,-0.30)},
    anchor=south,
    legend columns=-2
 }
 ]
  \addplot table [percentage series=1] {\data};
  \addplot table [percentage series=2] {\data};
  \legend{\strut Men, \strut Women}
  \end{axis}
  \end{tikzpicture}

Thanks

  • 1
    Welcome! Please edit your question to include code for a minimal document which we can compile to reproduce the problem. – cfr Sep 5 '17 at 2:41
  • 1
    The solution in tex.stackexchange.com/questions/99314/… might be able to solve your problem. – Long Gong Sep 5 '17 at 3:56

Browse other questions tagged or ask your own question.