簡體   English   中英

收到此錯誤錯誤:必須從色調調色板中請求至少一種顏色

[英]getting this error Error: Must request at least one colour from a hue palette

在此處輸入圖像描述我試圖堆疊上面給定的公式以在我的代碼中使用,但我不斷收到此錯誤錯誤:必須從色調調色板中請求至少一種顏色。

我正在嘗試構建一個分組條形圖,其中包含死亡、恢復和測試作為單獨的組,不同的大陸作為內部級別

代碼是這樣的:

 last_Day_data_graph<-lastDay_data %>%
  select(Continent, CumDeaths, CumRecovered, CumTests) %>%
  group_by(Continent)%>%
  summarise(sumCumDeaths=sum(CumDeaths), sumCumRecovered=sum(CumRecovered), sumCumTests=sum(CumTests))
last_Day_data_graph %>%
  tidyr::pivot_longer(cols = c(sumCumDeaths, sumCumRecovered, sumCumTests),
                      names_to = "variable",
                      values_to = "value") %>%
  dplyr::group_by(variable, value) %>%
  dplyr::summarise(n = dplyr::n()) %>%
  dplyr::mutate(value = factor(value,levels = c("Africa", "Asia", "Europe", "North America", "Oceania", "South America"))) %>%
  ggplot(ggplot2::aes(variable, n)) +
  geom_bar(ggplot2::aes(fill = value),
                    position = "dodge",
                    stat = "identity")

從提供的數據框作為圖片開始:

df <- structure(list(Continent = c("Africa", "Asia", "Europe", "North America", 
"Oceania", "South America"), sumCumDeaths = c(829L, 10864L, 42563L, 
42896L, 25L, 6198L), sumCumRecovered = c(9294L, 167396L, 165889L, 
110668L, 2935L, 42564L), sumCumTests = c(432064L, 3160072L, 7323075L, 
4803294L, 127006L, 291871L)), class = "data.frame", row.names = c(NA, 
-6L))

我們必須更改您的代碼中的一些內容。 以下是我們如何做到這一點的建議:

library(tidyverse)

df %>%
  tidyr::pivot_longer(cols = c(sumCumDeaths, sumCumRecovered, sumCumTests),
                      names_to = "variable",
                      values_to = "value") %>%
  dplyr::group_by(Continent, variable) %>%
  dplyr::mutate(variable = fct_relevel(variable, c("Africa", "Asia", "Europe", "North America", "Oceania", 
                                            "South America"))) %>%
  ggplot(ggplot2::aes(Continent, y = log(value), fill=variable)) +
  geom_col(position = position_dodge())

在此處輸入圖像描述

或者另一種選擇是:

df %>%
  tidyr::pivot_longer(cols = c(sumCumDeaths, sumCumRecovered, sumCumTests),
                      names_to = "variable",
                      values_to = "value") %>%
  dplyr::group_by(Continent, variable) %>%
  dplyr::mutate(variable = fct_relevel(variable, c("Africa", "Asia", "Europe", "North America", "Oceania", 
                                            "South America"))) %>%
  ggplot(ggplot2::aes(variable, y = log(value), fill=Continent)) +
  geom_col(position = position_dodge())

在此處輸入圖像描述

暫無
暫無

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

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