How to add boxplots to scatterplot with jitter

前端 未结 4 983
闹比i
闹比i 2020-12-04 16:51

I am using following commands to produce a scatterplot with jitter:

ddf = data.frame(NUMS = rnorm(500), GRP = sample(LETTERS[1:5],500,replace=T))
library(lat         


        
4条回答
  •  再見小時候
    2020-12-04 17:31

    To do this in ggplot2, try:

    ggplot(ddf, aes(x=GRP, y=NUMS)) + 
      geom_boxplot(outlier.shape=NA) + #avoid plotting outliers twice
      geom_jitter(position=position_jitter(width=.1, height=0))
    

    ggplot2 version of boxplot + jitter

    Obviously you can adjust the width and height arguments of position_jitter() to your liking (although I'd recommend height=0 since height jittering will make your plot inaccurate).

提交回复
热议问题