语境:
两组人(样本A/样本B)被要求针对六个类别表达自己的观点。
但是有些人没有给出答案。因此,我尝试将这些信息整合到我的分组条形图中(缺失信息量)。
问题:
我考虑过在 F 和“missing”之间集成一条分隔线,但我还没有找到如何做到这一点。
您有解决方案或者其他更合理的解决方案建议吗?
可选设计相关问题:
您会在 y 轴上添加整个 100% 缩放比例吗(参见 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}
答案1
您指的是这样的事情吗?
我添加了虚线
\path (axis cs:F,0) -- coordinate (m) (axis cs:missing,0);
\draw [dashed] (m) -- (current axis.north -| m);
对于可选问题,我想两个选项都可以。
\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}