How to add boxplots to scatterplot with jitter

前端 未结 4 981
闹比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条回答
  •  -上瘾入骨i
    2020-12-04 17:21

    I've written an R function called spreadPoints() within a package basiclotteR. The package can be directly installed into your R library using the following code:

    install.packages("devtools")
    library("devtools")
    install_github("JosephCrispell/basicPlotteR")
    

    For the example provided, I used the following code to generate the example figure below.

    ddf = data.frame(NUMS = rnorm(500), GRP = sample(LETTERS[1:5],500,replace=T))
    
    boxplot(NUMS ~ GRP, data = ddf, lwd = 2, ylab = 'NUMS')
    
    spreadPointsMultiple(data=ddf, responseColumn="NUMS", categoriesColumn="GRP",
                         col="blue", plotOutliers=TRUE)
    

    It is a work in progress (the lack of formula as input is clunky!) but it provides a non-random method to spread points on the X axis that doubles as a violin like summary of the data. Take a look at the source code, if you're interested.

提交回复
热议问题