Overdraw mean points in grouped boxplot with ggplot2

前端 未结 1 884
再見小時候
再見小時候 2021-01-12 06:08

I have a grouped boxplot with ggplot2 like this

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

and I wa

1条回答
  •  伪装坚强ぢ
    2021-01-12 06:19

    You should set position to position_dodge() and width to 0.75 - so points will be placed in the same way as boxplots.

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

    0 讨论(0)
提交回复
热议问题