【问题标题】:Labelling quartiles in the Boxplot using R使用 R 在箱线图中标记四分位数
【发布时间】:2021-07-12 02:47:59
【问题描述】:

我正在绘制箱线图并用四分位数和最小值-最大值对其进行标记。它适用于几列;但是,对于某些列,统计数据值与箱线图统计数据不完全匹配。

例如,summary 命令给出的median 值为2320,而boxplot.stats 给出的值为2319.5

我使用Statlog (German Credit Data) Data Set 进行信用风险评分。

数据集链接:https://archive.ics.uci.edu/ml/datasets/statlog+(german+credit+data)

【问题讨论】:

    标签: r plot label boxplot quartile


    【解决方案1】:

    不同的函数可以以不同的方式格式化值。打印值基于options("digits") 中设置的值,通常约为 7 位有效数字(不是小数位),但很少是精确值。除了系统设置外,该功能还可以设置不同的数值来显示数字。查看内部存储的整个值的唯一方法是使用dput()

    set.seed(42)
    x <- runif(25)
    summary(x)
    #    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    # 0.08244 0.45774 0.65699 0.61295 0.91481 0.98889 
    dput(summary(x))
    # structure(c(Min. = 0.0824375580996275, `1st Qu.` = 0.45774177624844, 
    # Median = 0.656992290401831, Mean = 0.612946688365191, `3rd Qu.` = 0.914806043496355, 
    # Max. = 0.988891728920862), class = c("summaryDefault", "table"))
    boxplot.stats(x)
    # $stats
    # [1] 0.08243756 0.45774178 0.65699229 0.91480604 0.98889173
    # 
    # $n
    # [1] 25
    # 
    # $conf
    # [1] 0.5125600 0.8014246
    # 
    # $out
    # numeric(0)
    # 
    dput(boxplot.stats(x))
    # list(stats = c(0.0824375580996275, 0.45774177624844, 0.656992290401831, 
    # 0.914806043496355, 0.988891728920862), n = 25L, conf = c(0.51255998195149, 
    # 0.801424598852172), out = numeric(0))
    

    请注意,这两个函数计算的中位数相同,但 boxplot.stats 打印出更多小数位。中位数以外的分位数的另一个因素是有不同的计算方法。 quantile 函数提供 9 种不同的方法(参见 ?quantile)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      相关资源
      最近更新 更多