How to add a line in boxplot?

后端 未结 5 961
日久生厌
日久生厌 2021-02-04 09:14

I would like to add lines between \"mean\" in my boxplot.

My code:

library(ggplot2)
library(ggthemes)

Gp=factor(c(rep(\"G1\",80),rep(\"G2\",80)))
Fc=fac         


        
5条回答
  •  爱一瞬间的悲伤
    2021-02-04 09:59

    Here's an alternative:

    DATA$U <- paste(X, Z) # Extra interaction
    qplot(U, Y, data = DATA, geom = "boxplot", fill = Z, na.rm = TRUE, 
          outlier.size = NA, outlier.colour = NA) +
      facet_grid(Gp ~ Fc) + theme_light() + scale_colour_gdocs() +
      theme(legend.position = "bottom") + 
      stat_summary(fun.y = mean, geom = "point", shape = 23, position = position_dodge(width = .75)) +
      stat_summary(fun.y = mean, geom = "line", aes(group = X)) + # Lines
      scale_x_discrete(labels = rep(levels(X), each = 2)) + xlab("X") # Some fixes
    

提交回复
热议问题