2013-08-30 51 views
6

我有一個分組箱線圖與GGPLOT2這樣在透支平均點編組箱線圖與GGPLOT2

p <- qplot(factor(cyl), mpg, data=mtcars, geom="boxplot", fill=factor(gear)) 

,我想透支的平均分。我試過這個

p+ stat_summary(fun.y=mean, colour="red", geom="point") 

但是,我沒有得到每個組的框的平均分。 enter image description here

我該怎麼做才能做到這一點?

回答

12

您應該將位置設置爲position_dodge()width爲0.75 - 因此點將以與箱形圖相同的方式放置。

qplot(factor(cyl), mpg, data=mtcars, geom="boxplot", fill=factor(gear)) + 
    stat_summary(fun.y=mean, colour="red", 
      geom="point",position=position_dodge(width=0.75))