我如何指示pgfplots
从一列中有标识符(Label
在下面的示例中)且另一列中有数据(Value
在下面的示例中)的数据集生成箱线图?我希望该图与第一个图相似,但不必为每个值手动创建单独的数据集Label
。
示例数据:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{statistics}
\usepackage{pgfplotstable}
\pgfplotstableset{%
columns/Label/.style={string type},
}
\pgfplotstablenew[%
create on use/Label/.style={create col/set={A}},
create on use/Value/.style={create col/expr={rand}},
columns={Label,Value}
]{10}\Asamples
\pgfplotstablenew[%
create on use/Label/.style={create col/set={B}},
create on use/Value/.style={create col/expr={rand}},
columns={Label,Value}
]{10}\Bsamples
\pgfplotstablenew[%
create on use/Label/.style={copy column from table={\Asamples}{Label}},
create on use/Value/.style={copy column from table={\Asamples}{Value}},
columns={Label,Value}
]{10}\ABsamples
\pgfplotstablevertcat{\ABsamples}{\Bsamples}%
\begin{document}
% Works fine
\begin{tikzpicture}
\begin{axis}[
ytick={1,2},
yticklabels={Group A, Group B},
]
\addplot[boxplot] table[y=Value] \Asamples;
\addplot[boxplot] table[y=Value] \Bsamples;
\end{axis}
\end{tikzpicture}
% Does not work as intended
% The plot should be similar to the above
% with one box for A and one for B
\begin{tikzpicture}
\begin{axis}[
ytick={1,2},
yticklabels={Group A, Group B},
]
\addplot[boxplot] table[x=Label,y=Value] \ABsamples;
\end{axis}
\end{tikzpicture}
\end{document}