我制作了以下图表:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[title = {Lengths of Amplification and Deletion Regions},ylabel = {$log_{10}(Length)$},
boxplot/draw direction=y,
xtick={1,2,3},
xticklabels={Amplification, Deletion, Both},
x tick label style={font=\footnotesize, text width=2.5cm, align=center}
]
\addplot+[mark = *, mark options = {red},
boxplot prepared={
lower whisker=2.214844,
lower quartile=3.608312,
median=3.895478,
upper quartile=4.447298,
upper whisker=4.666284
}, color = red
] coordinates{(0,4.832228)(0,5.513942)(0,6.29165)(0,5.216712)(0,5.677036)(0,4.981995)(0,5.172095)(0,4.056417)};
\addplot+[mark = *,mark options = {blue},
boxplot prepared={
lower whisker=3.508799,
lower quartile=5.079821,
median=5.481519,
upper quartile=5.971588,
upper whisker=6.250831
}, color = blue
] coordinates{(0,6.508115)(0,6.486354)(0,6.860059)(0,6.620663)(0,7.312391)(0,7.357306)(0,6.421694)
(0,6.479597)(0,6.690945)(0,6.661593)(0,7.271025)(0,6.396931)(0,7.035161)(0,7.371248)(0,7.033689)
(0,7.002645)(0,6.590617)(0,7.171933)(0,6.416259)(0,5.552438)};
\addplot+[mark = *,mark options = {green},
boxplot prepared={
lower whisker=2.437751,
lower quartile=3.334956,
median=4.336029,
upper quartile=5.068459,
upper whisker=5.265037
}, color = green
] coordinates{(0,5.826492)(0,5.819791)(0,6.21436)(0,4.47166)};
\end{axis}
\end{tikzpicture}
\end{document}
这使:
每个图表中线附近的圆圈代表相应组的平均值(对数转换)。我想将这些点变成星星,并在括号中用黑色写出相应的平均值:4.06、5.55 和 4.47。
答案1
要在箱线图上显示平均值,您可以使用average
键boxplot
。
我只改变了中间的黑白图,但你可以看看如何做其他的。我还纠正了是轴标签。读取手册,第 430-450 页,了解如何向平均值添加标签以及更改颜色。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[title = {Lengths of Amplification and Deletion Regions},ylabel =
{$\log_{10}(\hbox{Length})$},
boxplot/draw direction=y,
xtick={1,2,3},
xticklabels={Amplification, Deletion, Both},
x tick label style={font=\footnotesize, text width=2.5cm, align=center}
]
\addplot+[mark = *, mark options = {red},
boxplot prepared={
lower whisker=2.214844,
lower quartile=3.608312,
median=3.895478,
upper quartile=4.447298,
upper whisker=4.666284
}, color = red
] coordinates{(0,4.832228)(0,5.513942)(0,6.29165)(0,5.216712)(0,5.677036)(0,4.981995)(0,5.172095)(0,4.056417)};
\addplot+[mark = *,mark options = {blue},
boxplot prepared={
lower whisker=3.508799,
lower quartile=5.079821,
median=5.481519,
average=5.442438,
upper quartile=5.971588,
upper whisker=6.250831
}, color = blue
] coordinates{(0,6.508115)(0,6.486354)(0,6.860059)(0,6.620663)(0,7.312391)(0,7.357306)(0,6.421694)
(0,6.479597)(0,6.690945)(0,6.661593)(0,7.271025)(0,6.396931)(0,7.035161)(0,7.371248)(0,7.033689)
(0,7.002645)(0,6.590617)(0,7.171933)(0,6.416259)};
\addplot+[mark = *,mark options = {green},
boxplot prepared={
lower whisker=2.437751,
lower quartile=3.334956,
median=4.336029,
upper quartile=5.068459,
upper whisker=5.265037
}, color = green
] coordinates{(0,5.826492)(0,5.819791)(0,6.21436)(0,4.47166)};
\end{axis}
\end{tikzpicture}
\end{document}