如何在 R 中找到箱线图的上限和下限?

How can I find the upper and the lower limits of a boxplot in R?

enter image description here我在 R 中用某些参数构建了一个箱线图,但我不知道代码可以帮助我了解箱子的上限和下限。如果有人可以提供帮助,我将不胜感激。我知道数量只是不知道上限和下限。

您可以在 boxplot 函数中设置 range 参数。 在帮助页面上您可以找到详细信息:

range: this determines how far the plot whiskers extend out from the box. If range is positive, the whiskers extend to the most extreme data point which is no more than range times the interquartile range from the box. A value of zero causes the whiskers to extend to the data extremes.

分位数间距就是 75% 分位数和 25% 分位数之间的差值。

您可以查看箱线图的检查 stats。考虑以下示例:

set.seed(5)
x = rnorm(20)

my.boxplot = boxplot(x)

这将绘制以下箱线图

为了找到上下须线和四分位数的值,我们可以检查箱线图对象的stats

> my.boxplot$stats
           [,1]
[1,] -2.1839668   # Lower whisker
[2,] -0.8213175   # Q1
[3,] -0.3789700   # Q2 (median)
[4,]  0.1041255   # Q3
[5,]  1.3843593   # Upper whisker

# Equvalently:
boxplot(x)$stats
           [,1]
[1,] -2.1839668   # Lower whisker
[2,] -0.8213175   # Q1
[3,] -0.3789700   # Q2 (median)
[4,]  0.1041255   # Q3
[5,]  1.3843593   # Upper whisker

要获取离群值,您可以使用以下方法:

> my.boxplot$out
[1] 1.711441   # This example has only one outlier

# or
> boxplot(x)$out
[1] 1.711441   # This example has only one outlier