2014-09-03 75 views
2

我需要將鬍鬚(或水平線)添加到我的多個箱形圖中。將鬍鬚(水平線)添加到多個箱形圖

你可以找到我的數據集在這裏:link to data is broken...

換句話說,我繪製三個變量(墊,伊達和日誌)按性別(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")) 

回答

2

你可以使用stat_boxplot(geom ='errorbar')

我提供了一個例子:

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

結果:

enter image description here