getting this error Error: Must request at least one colour from a hue palette
getting this error Error: Must request at least one colour from a hue palette
enter image description here我试图叠加上面给定的公式以在我的代码中使用,但我不断收到此错误
错误:必须从色调调色板中请求至少一种颜色。
我正在尝试构建一个分组条形图的图表,将死亡、康复和测试作为单独的组,其中不同的大陆作为内部水平
代码是这样的:
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())
enter image description here我试图叠加上面给定的公式以在我的代码中使用,但我不断收到此错误 错误:必须从色调调色板中请求至少一种颜色。
我正在尝试构建一个分组条形图的图表,将死亡、康复和测试作为单独的组,其中不同的大陆作为内部水平
代码是这样的:
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())