在多个箱线图中添加“胡须”(水平线)。

3
我需要在我的多个箱线图中添加须线(或水平线)。您可以在此处找到我的数据集:链接已损坏... 换句话说,我正在绘制三个变量(Mat、Ita和Log),并按性别(F和M)进行分组,以比较它们的箱线图。我需要在每个箱线图中的两条垂直线末端添加一条水平线。我正在使用ggplot2包,目前正在使用的代码是(此代码允许我按照需要创建箱线图,我只需要添加水平线即可):
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"))
1个回答

4
你可以使用stat_boxplot(geom ='errorbar')
我提供一个示例:
bp <- ggplot(iris, aes(factor(Species), Sepal.Width, fill = Species))
bp + geom_boxplot() + stat_boxplot(geom ='errorbar') 

结果:

在此输入图片描述

(注:该图片无法翻译,仅提供原图)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接