问题描述
我需要在我的多个箱形图中添加晶须(或水平线).
I need to add whisker (or horizontal lines) to my multiple box-plots.
您可以在这里找到我的数据集:到数据的链接已损坏...
You can find my dataset here: link to data is broken...
换句话说,我正在绘制三个变量(Mat,Ita和Log)除以性别(F和M),以比较它们的箱形图.我需要在每个箱形图的两条垂直线的末尾添加一条水平线.
In other words, I am plotting three variables (Mat, Ita, and Log) divided by Gender (F and M), in order to compare their box plots. I need to add an horizontal line at the end of both vertical lines in each box plot.
我正在使用ggplot2程序包,到目前为止,我使用的代码是(此代码允许我根据需要创建箱形图,只需要添加水平线即可):
I am using ggplot2 package and the code I am using so far is (this code allows me to create the box plots as I need them, I only need to add the horizontal lines):
ggplot(newdata,aes(x=variable,y=value)) +
geom_boxplot(aes(fill=Gender)) +
xlab("Subject") +
ylab("Quiz score") +
ggtitle("Boxplots for quiz score and gender") +
scale_fill_manual(values=c("pink","lightblue"),labels=c("Female","Male")) +
theme(plot.title = element_text(face="bold"))
推荐答案
您可以使用stat_boxplot(geom ='errorbar')
我提供一个例子:
bp <- ggplot(iris, aes(factor(Species), Sepal.Width, fill = Species))
bp + geom_boxplot() + stat_boxplot(geom ='errorbar')
结果:
这篇关于将晶须(水平线)添加到多个箱形图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!