给定25,50,75个百分位数以及最小值和最大值在R中绘制bloxplots [英] Draw bloxplots in R given 25,50,75 percentiles and min and max values

查看:137
本文介绍了给定25,50,75个百分位数以及最小值和最大值在R中绘制bloxplots的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:


我有一个表格,其中每个row是一个不同的样本,每列分别是名称,最小值,最大值,平均值,第25个百分点,第50个百分点和第75个百分点。这是一个示例。

  sample1 1 38 10 8 10 13 
sample2 1 39 10 9 11 14
sample3 2 36 11 10 10 13

我想知道如何使用此数据格式以绘制箱线图,因为那是实际绘制的数据。上面的格式是一个制表符分隔的表。谢谢

这篇文章显示了如何使用 bxp 做到这一点是 boxplot 使用的函数,但是您需要按照正确的顺序放置数据,第一行是最小值,最后一行是最大值。



首先,读入数据

  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)

然后,按顺序排列,然后 t 转悠

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

并绘制

  bxp(list(stats = dat2,n = rep(10,ncol(dat2))))#n是在每组


Possible Duplicate:
geom_boxplot with precomputed values

I have a table where each row is a different sample and each column is the name, minimum, maximum, mean, 25th percentile, 50th percentile, 75th percentile respectively. Here is a sample.

sample1   1   38   10   8    10   13
sample2   1   39   10   9    11   14
sample3   2   36   11   10   10   13

I would like to know how I can use the data in this format in order to plot boxplots since that is the data that is actually plotted. The format above is a tab separated table. Thanks

解决方案

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

这篇关于给定25,50,75个百分位数以及最小值和最大值在R中绘制bloxplots的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆