Add whiskers (horizontal lines) to multiple boxplots

萝らか妹 提交于 2019-12-24 04:34:12

问题


I need to add whisker (or horizontal lines) to my multiple box-plots.

You can find my dataset here: link to data is broken...

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.

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"))

回答1:


You could use stat_boxplot(geom ='errorbar')

I provide an example:

bp <- ggplot(iris, aes(factor(Species), Sepal.Width, fill = Species))
bp + geom_boxplot() + stat_boxplot(geom ='errorbar') 

Result:



来源:https://stackoverflow.com/questions/25641792/add-whiskers-horizontal-lines-to-multiple-boxplots

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!