我正在尝试使用 Covid19 Cases 为各个州创建ggridges图。我想根据病例数填充颜色,而不是基于州,但无法这样做。
到目前为止,我已经尝试过以下代码:
library(tidyverse)
library(lubridate)
library(ggridges)
df_ind_stacked_daily <- read.csv(url("https://raw.githubusercontent.com/johnsnow09/covid19-df_stack-code/main/df_ind_stacked_daily.csv")) %>%
mutate(Date = ymd(Date))
工作代码:
df_ind_stacked_daily %>%
filter(Daily_cases_type == "Daily_confirmed",
State.UnionTerritory != "India") %>%
ggplot(aes(x = Date, y = State.UnionTerritory,
height = Daily_cases_counts, group = State.UnionTerritory)) +
geom_density_ridges(stat = "identity", alpha = .8,) + # , scale = 2
coord_cartesian(clip = "off") +
theme_ridges(grid = FALSE)
问题:当我尝试根据高度美学填充颜色时,它不起作用
df_ind_stacked_daily %>%
filter(Daily_cases_type == "Daily_confirmed",
State.UnionTerritory != "India") %>%
ggplot(aes(x = Date, y = State.UnionTerritory, fill = Daily_cases_counts,
height = Daily_cases_counts, group = State.UnionTerritory)) +
geom_density_ridges_gradient(stat = "identity", scale = 2, rel_min_height = 0.01, gradient_lwd = 1.) +
coord_cartesian(clip = "off") +
theme_ridges(grid = FALSE)