如何仅使用min,max,median,lower fourth,upper 4th和offliers在RStudio中创建一个boxplot?

时间:2015-09-11 17:19:43

标签: r

我试图创建一个箱线图,但我知道的唯一数据是最小值,最大值,中位数,低四度,高四度和异常值。 这是我的数据:

  • 分钟:188.1
  • 最大:230.5
  • 下四:196.0
  • 中位数:202.2
  • 上四:216.8
  • 异常值:125.8,250.2

我已经能够用:

创建箱形图
dat<-read.table(text = "188.1 196.0 202.2 216.8 230.5")
dat<-t(dat)
bxp(list(stats=dat, n=rep(10, ncol(dat))))

但我不知道如何给它异常值并让它显示出来。我只发现了如何摆脱异常值的问题,但我需要知道如何展示它们。我该怎么做?

2 个答案:

答案 0 :(得分:2)

只需将其他参数outgroups添加到您传递到bxp()的统计信息摘要列表中:

bxp(list(stats = dat, n = rep(10, ncol(dat)),
         out = c(125.8, 250.2), groups = c(1,1)))

enter image description here

要了解您如何自己学习,请查看?bxp,其中包含对其第一个参数的描述:

z: a list containing data summaries to be used in constructing
   the plots.  These are usually the result of a call to
   ‘boxplot’, but can be generated in any fashion.

嗯。看起来很有希望。要详细了解调用boxplot()产生的数据摘要的确切类型,我们可以查看"Value"部分?boxplot,我们会在其中找到包含以下组件的列表(其中包括):

  out: the values of any data points which lie beyond the extremes
       of the whiskers.

group: a vector of the same length as ‘out’ whose elements indicate
       to which group the outlier belongs.

答案 1 :(得分:0)

喜欢这样?

dat<-read.table(text = "188.1 196.0 202.2 216.8 230.5")
dat<-t(dat)

xp <- 30
plot(0, type = 'n', ylim=range(dat[,1]) + c(-xp, xp))
bxp(list(stats=dat, n=rep(10, ncol(dat))), add = TRUE)

outliers <- c(250, 160)
points(rep(1, length(outliers)), outliers)

基本上只需将其添加为次要图,其范围可以解释异常值。我只是把xp和winpw扩展变量,但你可以改变ylim = range(异常值)