我想创建一个表,其中行是树,列是数据集,其中每个数据集在表中都有一个与每棵树相对应的箱线图,但我无法正确地做到这一点,箱线图图像不是从顶部开始的,所以它没有与每棵树对齐,我无法找到一种方法将它稍微向上移动
以下是代码
\usepackage{tikz}
\usepackage{dcolumn}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{lscape}
\usepackage{verbatim}
\usepackage{pgfplots}
\listfiles
\usepackage{amssymb}
\usepackage{graphicx}
\pgfplotsset{width = 4cm ,compat=1.8}
\begin{document}
\usetikzlibrary{pgfplots.statistics}
\newcommand{\Abox}{
\begin{tikzpicture}[inner sep = 0pt ,outer sep = 0pt,trim axis left,trim axis right,baseline ]
\begin{axis} [y=2*\baselineskip,
ymax = 15,
ymin = 0,
ytick=\empty,
%axis line style={draw=none},
tick style={draw=none}
]
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=1
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=2
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=3
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=4
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=5
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=6
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=7
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=8
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=9
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=10
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=11
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=12
},
] coordinates {};\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=13
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=0.6,
lower quartile=0.5,
upper whisker=0.8,
lower whisker=0.4,
draw position=14
},
] coordinates {};
\end{axis}
\end{tikzpicture}
}
\begin{table}[h!]
\centering
\begin{tabular}{l l c l c l c}
\toprule
& \multicolumn{2}{c}{ DATASET I} & \multicolumn{2}{c}{ DATASET II} & \multicolumn{2}{c}{ DATASET III}
\\\cmidrule(r){2-3}\cmidrule(lr){4-5}\cmidrule(l){6-7}
& mean & \multirow{2}{*}{boxplot} & mean & \multirow{2}{*}{boxplot} & mean & \multirow{2}{*}{boxplot} \\
& sd. & & sd. & & sd & \\
\midrule
\multirow{2}{*}{Tree 1} & -0.96 & \multirow{28}{2.6cm}{\Abox} & -0.42 &\multirow{28}{2.6cm}{\Abox} & 2.5&\multirow{28}{2.6cm}{\Abox} \\
&2.6 & &&&& \\
\multirow{2}{*}{Tree 2} & 0.09 & & 0.04 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 3} & 0.29 & & 0.10 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 4} & 0.84 & & 0.30 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 5} & 2.19 & & 0.80 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 6} & 1.02 & & 0.37 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 7} & -0.10 & & -0.03 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 8} & -1.11 & & -0.30 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 9} & 1.15 & & 0.32 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 10} & -1.34 & & -0.38 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 11} & 0.43 & & 0.12 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 12} & -0.37 & & -0.10 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 13} & 0.41 & & 0.12 &&& \\
&&&&&& \\
\hline
\multirow{2}{*}{TOBA } & -0.69 & & -0.20 &&& \\
&&&&&& \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
我可能更愿意创建一个宏来为您生成单个箱线图并将其放在表格中:
\documentclass{article}
\usepackage{geometry}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{pgfplots}
\pgfplotsset{width = 4cm, compat=1.8}
\begin{document}
\usetikzlibrary{pgfplots.statistics}
\newcommand{\bplot}[5][blue]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
xmin=0,
xmax=1,
y=1.5*\baselineskip,
axis line style={draw=none},
tick style={draw=none},
ticks=none,
yticklabels=\empty.
]
\addplot+ [
draw=#1,
boxplot prepared={
upper quartile=#2,
lower quartile=#3,
upper whisker=#4,
lower whisker=#5,
},
] coordinates {};
\end{axis}
\end{tikzpicture}%
}
\begin{table}[h!]
\centering
\begin{tabular}{l l c l c l c}
\toprule
& \multicolumn{2}{c}{ DATASET I} & \multicolumn{2}{c}{ DATASET II} & \multicolumn{2}{c}{ DATASET III} \\\cmidrule(r){2-3}\cmidrule(lr){4-5}\cmidrule(l){6-7}
& mean & \multirow{2}{*}{boxplot} & mean & \multirow{2}{*}{boxplot} & mean & \multirow{2}{*}{boxplot} \\
& sd. & & sd. & & sd & \\
\midrule
\multirow{2}{*}{Tree 1} & -0.96 & \multirow{2}{2.6cm}{\bplot{0.6}{0.5}{0.8}{0.4}} & -0.42 & \multirow{2}{2.6cm}{\bplot{0.6}{0.5}{0.8}{0.4}} & 2.5 & \multirow{2}{2.6cm}{\bplot{0.6}{0.5}{0.8}{0.4}} \\
&2.6 & &&&& \\
\multirow{2}{*}{Tree 2} & 0.09 & \multirow{2}{2.6cm}{\bplot[red]{0.7}{0.3}{0.9}{0.2}} & 0.04 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 3} & 0.29 & \multirow{2}{2.6cm}{\bplot[brown, densely dashed]{0.5}{0.2}{0.6}{0.1}} & 0.10 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 4} & 0.84 & & 0.30 &&& \\
&&&&&& \\
\multirow{2}{*}{Tree 5} & 2.19 & & 0.80 &&& \\
&&&&&& \\
\multicolumn{7}{c}{\centering --------- et cetera ---------} \\
\midrule
\multirow{2}{*}{TOBA } & -0.69 & & -0.20 &&& \\
&&&&&& \\
\bottomrule
\end{tabular}
\end{table}
\end{document}