can one offset jitter points in ggplot boxplot

前端 未结 1 1099
礼貌的吻别
礼貌的吻别 2021-01-05 12:48

In a ggplot boxplot, it is easy to use jitter to add the raw data points with varying degrees of jitter. With zero jitter the following code

dat         


        
相关标签:
1条回答
  • 2021-01-05 13:35

    If we convert group to numeric and then add an offset, you seem to get your desired output. There is probably a more effective / efficient way, but give this a whirl:

    ggplot(dat, aes(group, values)) + 
      geom_boxplot(outlier.size = 0) + 
      geom_point(aes(x = as.numeric(group) + .25, colour=group), alpha=0.7) + 
      ylim(0, 1) + stat_summary(fun.y=mean, shape=3, col='red', geom='point') +
      opts(legend.position = "right") + ylab("values") + xlab("group")
    

    enter image description here

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