Draw bloxplots in R given 25,50,75 percentiles and min and max values [duplicate]

与世无争的帅哥 提交于 2019-11-28 12:46:03
GSee

This post shows how you can do this with bxp which is the function that boxplot uses, but you need to put your data in the right order with the first row being the minimum, and the last row being the maximum.

First, read in the data

dat <- read.table(text="sample1   1   38   10   8    10   13
sample2   1   39   10   9    11   14
sample3   2   36   11   10   10   13", row.names=1, header=FALSE)

Then, put in order and transpose

dat2 <- t(dat[, c(1, 4, 5, 6, 2)]) #Min, 25pct, 50pct, 75pct, Max

and plot

bxp(list(stats=dat2, n=rep(10, ncol(dat2)))) #n is the number of observations in each group

This is a duplicate, however for posterity and since I already started writing...

dat <- data.frame(name=paste0('sample',1:3), min=c(1,1,2), max=c(38,39,36), mean=c(10,10,11), q25=c(8,9,10), q50=c(10,11,10), q75=c(13,14,13))

ggplot(dat, aes(x=name, ymin=min, ymax=max, lower=q25, middle=q50, upper=q75))+geom_boxplot(stat='identity')
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!