gpt4 book ai didi

r - geom_boxplot 给出了错误的 mustache

转载 作者:行者123 更新时间:2023-12-04 10:49:39 24 4
gpt4 key购买 nike

我正在使用 ggplot2 中的 geom_boxplot 制作箱线图。但是,我发现 mustache 长度不正确,我不知道为什么。这是我的数据:

value = c(1.3739117,0.8709891,3.4510461,0.8470309,1.4838725,0.6942611,1.3095816,3.0444649,19.2785424,1.0866242,0.9376845,2.2343836, 20.7975509, 20.3102489, 18.0046679,1.4197519)
data = data.frame(value)
ggplot(data, aes(y = value)) +
stat_boxplot(geom = "errorbar", width = 0.3) +
geom_boxplot(width = 0.5)

我看到这样的情节:

enter image description here

第三个分位数与上部晶须重叠。我是手动计算的,结果如下:
summary(data)
Min. : 0.6943
1st Qu.: 1.0494
Median : 1.4518
Mean : 6.0715
3rd Qu.: 7.0895
Max. :20.7976

基于 geom_boxplot 的解释:上须从铰链延伸到最大值,距离铰链不超过 1.5 * IQR(其中 IQR 是四分位距,或第一和第三四分位数之间的距离)。下部晶须从铰链延伸到最小值,最多为铰链的 1.5 * IQR。

在我的情况下 IQR 是:7.0895-1.0494 = 6.0401

下须应为:0.6943 - 1.5*6.0401 = -8.36585

上须应为:7.0895 + 1.5*6.0401 = 16.14965

我知道负的下须是没有意义的,所以这里用最小值代替。但是为什么没有显示上面的晶须呢?我很困惑,我在网上找不到解决这个问题的例子。我对 ggplot 设置有什么误解?我非常感谢您的帮助和建议!

最佳答案

从引用部分:

The upper whisker extends from the hinge to the largest value no further than 1.5 * IQR from the hinge (where IQR is the inter-quartile range, or distance between the first and third quartiles).



“值”是指来自原始数据点。如果绘制数据,顶部铰链之间在 7.09 和 16.15 (+1.5*IQR) 之间没有值。如果这些四分位数是从其中一个值位于该范围内的数据中产生的,则上须线会出现在那里。
ggplot(data, aes(y = value)) +
geom_jitter(aes(x = 0.5), width = 0.05) +
stat_boxplot(geom = "errorbar", width = 0.3,
color = "red", size = 1.5) +
geom_boxplot(width = 0.5, alpha = 0.5) +
geom_hline(yintercept = c(7.09, 16.15), lty = "dashed")

enter image description here

关于r - geom_boxplot 给出了错误的 mustache ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59497080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com