【问题标题】:How to obtain values (e.g. median) from a boxplot in r?如何从 r 中的箱线图中获取值(例如中位数)?
【发布时间】:2020-07-10 16:23:22
【问题描述】:

我绘制了每年 PM2.5 水平的箱线图。

Boxplot(PM2.5~year, data=subset(dat, hour==12), las=1)

如何从箱线图中提取中位数等值?

【问题讨论】:

    标签: r plot boxplot median iqr


    【解决方案1】:

    默认的boxplot 函数不可见地返回摘要,您只需将其分配给一个变量:

    res <- boxplot(Sepal.Length ~ Species, data=iris)
    

    res 中存在一个元素stats

    > res$stats
         [,1] [,2] [,3]
    [1,]  4.3  4.9  5.6
    [2,]  4.8  5.6  6.2
    [3,]  5.0  5.9  6.5
    [4,]  5.2  6.3  6.9
    [5,]  5.8  7.0  7.9
    

    这些是方框的四分位数摘要。中位数是中间的,所以:

    > res$stats[3,]
    [1] 5.0 5.9 6.5
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-04
      • 2018-10-06
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 2014-08-23
      相关资源
      最近更新 更多