簡體   English   中英

R 中的警告消息

[英]Warning message in R

我正在嘗試更改堆疊條形圖上的 y label,因為它似乎使加起來為 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 為百分比。

我沒有看到任何警告,但我對你到底想要什么有點困惑。

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

上面是你的代碼,下面是 output 原始代碼

如果你想讓它加起來最多三個,那么你可以使用下面的代碼(去掉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

新代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM