2

Context:

Two groups (sample A / sample B) were asked to express their opinion in six categories.

However, some people did not give an answer. Hence, I am trying to integrate this information in my grouped bar chart (amount of missing information).

Question:

I considered integrating a single separator line between F and "missing, but I did not find out how to do so.

Do you have a solution or other suggestions for a more reasonable solution?

Optional design related question:

Would you add the whole 100% scaling at y-axis (cf. MWE) or is this somehow a redundant information for you?

MWE:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
compat=newest,
ybar = 0.6,
width=1\textwidth,
height=0.4\textheight,
ymin=0,
ymax=100,
enlarge x limits = 0.1,
x axis line style={opacity=1},
bar width=20pt,
legend style={at={(0.5,-0.15)},
    anchor=north,legend columns=0},
ylabel={[\%]},
symbolic x coords={A, B, C, D, E, F, missing},
xtick=data,
nodes near coords,
axis lines*=left,
y axis line style={opacity=1},
cycle list={
    {fill=black!60,draw=black!60},
    {fill=black!40,draw=black!40},
    {fill=black!20,draw=black!20}
},
axis on top,
legend style={draw=none,/tikz/every even column/.append style={column sep=0.5cm}}
]

\addplot+[fill=black!10, text=black] coordinates {(A,62.5) (B,0) (C,4.5) (D,11.4) (E,14.8) (F,1.1) (missing,2.3)};
\addplot[fill=black!70,text=black] coordinates {(A,15.0) (B,0) (C,5.8) (D,43.7) (E,18.4) (F,17) (missing,0)};

\legend{sample X, sample Y}

\end{axis}
\end{tikzpicture}

\end{document}
  • Nobody? Did I ask a wrong question? – Jens Jul 17 '19 at 17:53
1

Something like this you mean?

enter image description here

I added the dashed line with

\path (axis cs:F,0) -- coordinate (m) (axis cs:missing,0);
\draw [dashed] (m) -- (current axis.north -| m);

For the optional question, I think I'd be fine with either option.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
compat=newest,
ybar = 0.6,
width=1\textwidth,
height=0.4\textheight,
ymin=0,
ymax=100,
enlarge x limits = 0.1,
x axis line style={opacity=1},
bar width=20pt,
legend style={at={(0.5,-0.15)},
    anchor=north,legend columns=0},
ylabel={[\%]},
symbolic x coords={A, B, C, D, E, F, missing},
xtick=data,
nodes near coords,
axis lines*=left,
y axis line style={opacity=1},
cycle list={
    {fill=black!60,draw=black!60},
    {fill=black!40,draw=black!40},
    {fill=black!20,draw=black!20}
},
axis on top,
legend style={draw=none,/tikz/every even column/.append style={column sep=0.5cm}}
]

\addplot+[fill=black!10, text=black] coordinates {(A,62.5) (B,0) (C,4.5) (D,11.4) (E,14.8) (F,1.1) (missing,2.3)};
\addplot[fill=black!70,text=black] coordinates {(A,15.0) (B,0) (C,5.8) (D,43.7) (E,18.4) (F,17) (missing,0)};

\legend{sample X, sample Y}

\path (axis cs:F,0) -- coordinate (m) (axis cs:missing,0);
\draw [dashed] (m) -- (current axis.north -| m);

\end{axis}
\end{tikzpicture}

\end{document}
|improve this answer|||||
  • Thanks! Pretty decent solution! :-) – Jens Jul 18 '19 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.