问题
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