How to add boxplots to scatterplot with jitter

前端 未结 4 982
闹比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:30

    For a lattice solution:

    library(lattice)
    ddf = data.frame(NUMS = rnorm(500), GRP = sample(LETTERS[1:5], 500, replace = T))
    bwplot(NUMS ~ GRP, ddf, panel = function(...) {
      panel.bwplot(..., pch = "|")
      panel.xyplot(..., jitter.x = TRUE)})
    

    The default median dot symbol was changed to a line with pch = "|". Other properties of the box and whiskers can be adjusted with box.umbrella and box.rectangle through the trellis.par.set() function. The amount of jitter can be adjusted through a variable named factor where factor = 1.5 increases it by 50%.

提交回复
热议问题