我正在整理调查数据,并想创建如下所示的条形图:
有人能给我提供一下那个图表的模板吗?我尝试过变形条形图并将两者粘在一起,但效果不太好。谢谢!
答案1
这看起来很相似,除了:
- 缺少竖起大拇指/竖起大拇指符号;
- 负值;
- 一些较小的问题。
\documentclass[tikz,border={40pt}]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis x line=top,
axis y line=none,
bar width=16pt,
xmax=25,
xmin=-25,
ymax=3.5,
ymin=-1,
width=9cm,
height=5cm,
nodes near coords,
point meta=explicit symbolic,
every node near coord/.append style={font=\tiny},
legend columns=2,
legend style={
at={(0.5,0)},
anchor=north}
]
\addplot[xbar,fill=blue!20,nodes near coords align={left}] plot coordinates{(10,0) [18 to 24] (15,1) [25 to 34] (7,2) [35 to 45] (17,3) [>45]};
\addlegendentry{Yes};
\addplot[xbar,fill=red!20,nodes near coords align={right}] plot coordinates{(-11,0) [18 to 24] (-13,1) [25 to 34] (-15,2) [35 to 45] (-8,3) [>45]};
\addlegendentry{No};
\draw (axis cs:0,-0.5) -- (axis cs:0,4);
\end{axis}
\end{tikzpicture}
\end{document}