'getting this error Error: Must request at least one colour from a hue palette

enter image description hereIm trying to stack the above given formula to use on my code, but i keep getting this error Error: Must request at least one colour from a hue palette.

I'm trying to build a graph of grouped bar chart with Deaths, recovered and Tests as seperate groups with different continents as the levels inside

Code is this:

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


Solution 1:[1]

Beginning with provided dataframe as picture:

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

We have to change some things in your code. Here is a suggestion how we could do it:

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

enter image description here

OR another option is:

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

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TarJae