gpt4 book ai didi

r - ggplot2警告:ymin!= 0时,堆栈定义不正确

转载 作者:行者123 更新时间:2023-12-03 08:58:07 29 4
gpt4 key购买 nike

也许答案只是被警告。我打算使用缩放和居中的变量来查看观测值与平均值之间的差异。这是一种常见的做法。但是当我这样做时,我从ggplot2收到警告。

Warning messages:
1: Stacking not well defined when ymin != 0

我喜欢让ggplot2和世界其他地方开心,并且没有任何警告出现。我尝试通过以下方式消除警告,并在SO中搜索了相关问题(请参阅底部的链接以找到一些更有希望的问题)。我的 friend ggplot2仍然警告我。

问题:
  • 如何使警告消失?
  • 我可以忽略警告吗?
  • 这种做法有什么问题吗?

  • 代码尝试:
    ## The data
    mtcars$scaled_mpg <- unlist(tapply(mtcars$mpg, mtcars$cyl, scale))
    mtcars <- mtcars[order(mtcars$cyl), ]
    mtcars$ID <- unlist(tapply(mtcars$cyl, mtcars$cyl, seq_along))
    mtcars$ID <- factor(sprintf("%02d", mtcars$ID ))

    ## ================ Attempt 1 ================
    ggplot(mtcars, aes(x = ID, y = scaled_mpg, fill = factor(cyl))) +
    geom_bar(stat="identity") + facet_grid(cyl~.)

    ## ================ Attempt 2 ================
    ggplot(mtcars, aes(x = ID, fill = factor(cyl))) +
    geom_bar(aes(weight = scaled_mpg)) + facet_grid(cyl~.)

    ## ================ Attempt 3 ================
    dat1 <- subset(mtcars, scaled_mpg >= 0)
    dat2 <- subset(mtcars, scaled_mpg < 0)

    ggplot() +
    geom_bar(data = dat1, aes(x = ID, y = scaled_mpg,
    fill = factor(cyl)),stat = "identity") +
    geom_bar(data = dat2, aes(x = ID, y = scaled_mpg,
    fill= factor(cyl)),stat = "identity") +
    facet_grid(cyl~.)

    剧情:

    类似文章:
  • set length of `geom_hline` in `geom_bar` plot
  • ggplot2 - stacking not well defined when ymin !=0
  • ggplot2 and a Stacked Bar Chart with Negative Values
  • 最佳答案

    1)通过将adding position = "identity"转换为geom_bar,或者使用

    suppressWarnings(print(ggplot(...)))

    2-3)考虑技术方面-是的,您可以忽略它。此警告的 reason与解释条的高度为负而不是负值有关。

    关于r - ggplot2警告:ymin!= 0时,堆栈定义不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19481634/

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