【问题标题】:Box plot problems箱线图问题
【发布时间】:2020-07-23 13:16:36
【问题描述】:

我对统计很陌生,但我正在使用 R 为我的硕士论文创建一些图表。到目前为止,我已经创建了一个箱形图,但是,当所说的箱形图看起来像这样时,我 90% 确定这是不正确的。

我使用的代码如下:

boxplot(Pollinators~Year, data=X_east_pool_park_realistic_results,
        main=toupper("Pollinators per Year"), font.main=3, cex.main=1.2,
        xlab="Year", ylab="Pollinators", font.lab=3, col="white")

我确信这有一个非常简单的解决方案,我只是没有设法遇到,但正如我在一开始所说的那样,我对此完全陌生。

TIA!

【问题讨论】:

  • 看起来正确。您的数据就是这样,正向倾斜。也许尝试在 y 轴上添加log = "y" 的对数刻度。或者使用直方图。
  • 您的数据中是否有很多 0 或非常少的计数?

标签: r data-visualization boxplot


【解决方案1】:

正如 Roman 所指出的,您的代码是正确的。该图看起来像这样,因为您的数据充满了零。您可以通过运行以下代码得到一个非常相似的图表:

boxplot( c(0,0,0,0,0,0,1,1,2,10) )

由于 R 中箱形图的定义,带有膨胀零的数据看起来像这样:箱形覆盖从第一个分位数到第三个分位数,黑条是中位数。如果您的大多数数据为零,则零将是中位数,并且第一个分位数将相等,因此您的盒子上不会有底部。

根据您的数据,这是预期的。我不是专门从事授粉的,但我猜你的很多植物都没有被传粉者访问过,有些植物被很多人访问过。根据问题,从数据集中删除未访问的植物可能会很有趣。

【讨论】:

    【解决方案2】:

    为了提供一些取证,您的数据中似乎发生了类似的事情。每个Year 的零的数量似乎与观察的数量有关(例如因子二)。

    v1 <- cbind(Pollinators=c(rep(0, 3000), 0:1500), Year=1)
    v2 <- cbind(Pollinators=c(rep(0, 6000), 0:3000), Year=2)
    v3 <- cbind(Pollinators=c(rep(0, 9000), 0:4500), Year=3)
    v4 <- cbind(Pollinators=c(rep(0, 12000), 0:6000), Year=4)
    v5 <- cbind(Pollinators=c(rep(0, 15000), 0:7500), Year=5)
    
    X_east_pool_park_realistic_results <- rbind(v1, v2, v3, v4, v5)
    
    boxplot(Pollinators~Year, data=X_east_pool_park_realistic_results,
            main=toupper("Pollinators per Year"), font.main=3, cex.main=1.2,
            xlab="Year", ylab="Pollinators", font.lab=3, col="white")
    

    【讨论】:

    • 不能是零的数量。显然,小数据点的数量更高。更改为例如v1 &lt;- cbind(Pollinators=c(rep(0.1, 3000), 0:1500), Year=1); v2 &lt;- cbind(Pollinators=c(rep(0.5, 6000), 0:3000), Year=2); v3 &lt;- cbind(Pollinators=c(rep(1, 9000), 0:4500), Year=3)
    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 2022-12-15
    • 2012-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-23
    相关资源
    最近更新 更多