r中的警告消息

发布于 2025-02-12 18:24:16 字数 802 浏览 2 评论 0原文

我正在尝试更改堆叠条形图上的Y标签,因为它似乎正在制作值总计3的值。

这是我的数据框架:

 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_continuul(limits = c(0,3))”,它起作用,但y为0.00-1.00)。

我不知道如何使其0-3而不是0-1。同样,如果数据集中的3个值超过1,为什么会真正混淆为什么要做0-1。

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

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

I am trying to change the y label on a stacked bar graph because it seems to be making values that add up to 3 add up to 1 instead.

Here is my data frame:

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

Here is my script for generating a stacked bar graph;

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))

which creates this warning message;

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

(Without "scale_y_continuous(limits=c(0,3))" it works but y is 0.00 - 1.00).

I can't figure out how to make it 0-3 rather than 0-1. Also just genuinely confused why it would do 0-1 if 3 of the values in the dataset are more than 1.

Let me know if any of this doesn't make sense.
Thank you in advance.

N.B. I have created exactly what I wanted with a different dataset that required y to be a percentage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以为你会在 2025-02-19 18:24:17

我没有看到任何警告,但是我对您的确切想要的东西有些困惑。

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 = “填充” part)

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

“新代码”

I am not seeing any warning, but I a little confused about what you exactly want.

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

Above is your code, and the output is below
Original code

If you want it to add up to three, then you can use the following code (remove the position = "fill" part)

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

new code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文