【问题标题】:Warning message in RR中的警告消息
【发布时间】:2022-08-20 03:29:41
【问题描述】:

我正在尝试更改堆叠条形图上的 y 标签,因为它似乎使加起来为 3 的值加起来为 1。

这是我的数据框:

 Morph Choice     Value
1 Orange Orange 1.7333330
2 Orange  Green 1.2666670
3  Green Orange 0.8666667
4  Green  Green 2.1333333

这是我生成堆叠条形图的脚本;

ggp2M<- ggplot(data = forbargraphMEANS.df,
              aes(x = Morph,
                  y = Value,
                  fill = Choice))+
  geom_bar(position = \"fill\", stat = \"identity\") + scale_y_continuous(limits=c(0,3))

创建此警告消息;

Warning message:
Removed 4 rows containing missing values (position_stack).

(没有 \"scale_y_continuous(limits=c(0,3))\" 它可以工作,但 y 是 0.00 - 1.00)。

我不知道如何使它成为 0-3 而不是 0-1。如果数据集中的 3 个值大于 1,为什么它会执行 0-1 也很困惑。

让我知道这是否有任何意义。 先感谢您。

注:我已经用一个不同的数据集创建了我想要的东西,它要求 y 是一个百分比。

  • 有了这些数据和这段代码,我不会收到任何警告。
  • 如果您想显示数据的“真实”比例,请尝试删除position=\"fill\",因为“position_fill() 堆叠条形并将每个堆叠标准化为具有恒定高度”为 1。

标签: r ggplot2


【解决方案1】:

我没有看到任何警告,但我对你到底想要什么有点困惑。

library(ggplot2)

forbargraphMEANS.df<- data.frame (Morph = c("Orange", "Orange", "Green", "Green"),
                  Choice = c("Orange", "Green", "Orange", "Green"),
                  Value = c(1.7333330, 1.2666670, 0.8666667, 2.1333333)
                  )
forbargraphMEANS.df

ggp2M<- ggplot(data = forbargraphMEANS.df,
              aes(x = Morph,
                  y = Value,
                  fill = Choice))+
  geom_bar(position = "fill", stat = "identity") + scale_y_continuous(limits=c(0,3))

ggp2M

以上是您的代码,输出如下

如果你想让它加起来最多三个,那么你可以使用下面的代码(去掉position = "fill"部分)

library(ggplot2)

forbargraphMEANS.df<- data.frame (Morph = c("Orange", "Orange", "Green", "Green"),
                  Choice = c("Orange", "Green", "Orange", "Green"),
                  Value = c(1.7333330, 1.2666670, 0.8666667, 2.1333333)
                  )
forbargraphMEANS.df

ggp2M<- ggplot(data = forbargraphMEANS.df,
              aes(x = Morph,
                  y = Value,
                  fill = Choice))+
  geom_bar(stat = "identity") + scale_y_continuous(limits=c(0,3))

ggp2M

【讨论】:

    猜你喜欢
    • 2012-02-09
    • 2017-10-13
    • 1970-01-01
    • 2023-03-14
    • 2014-05-31
    • 2016-07-05
    • 2016-08-22
    • 1970-01-01
    相关资源
    最近更新 更多