ggplot2: horizontal position of stat_summary with geom_boxplot

前端 未结 1 1194

I want to annotate mean of each boxplot using ggplot2. However, I could not figure out how to horizontally center the symbols marking the means within their res

相关标签:
1条回答
  • 2020-12-10 19:33

    Try with position_dodge()

    ggplot(data=mpg, mapping=aes(x=class, y=hwy)) + 
           geom_boxplot(aes(color = drv), outlier.shape = NA) +
           stat_summary(fun.y = mean, geom = "point", size=2, aes(shape = drv, color = drv), 
                        position = position_dodge(width = .75)) + 
           theme_bw()
    
    0 讨论(0)
提交回复
热议问题