diff --git a/README.Rmd b/README.Rmd index 70d250b9..af3934c5 100644 --- a/README.Rmd +++ b/README.Rmd @@ -49,9 +49,11 @@ secondary <- "#f9c80e" tertiary <- "#177245" fourth_colour <- "#A393BF" fifth_colour <- "#2e8edd" -colvec <- c(base = base, primary = primary, secondary = secondary, - tertiary = tertiary, fourth_colour = fourth_colour, - fifth_colour = fifth_colour) +colvec <- c( + base = base, primary = primary, secondary = secondary, + tertiary = tertiary, fourth_colour = fourth_colour, + fifth_colour = fifth_colour +) library(epiprocess) suppressMessages(library(tidyverse)) theme_update(legend.position = "bottom", legend.title = element_blank()) @@ -61,7 +63,7 @@ delphi_pal <- function(n) { } scale_fill_delphi <- function(..., aesthetics = "fill") { discrete_scale(aesthetics = aesthetics, palette = delphi_pal, ...) -} +} scale_color_delphi <- function(..., aesthetics = "color") { discrete_scale(aesthetics = aesthetics, palette = delphi_pal, ...) } @@ -124,7 +126,8 @@ cases <- pub_covidcast( time_type = "day", geo_type = "state", time_values = epirange(20200601, 20220101), - geo_values = "*") |> + geo_values = "*" +) |> select(geo_value, time_value, case_rate = value) deaths <- pub_covidcast( @@ -133,7 +136,8 @@ deaths <- pub_covidcast( time_type = "day", geo_type = "state", time_values = epirange(20200601, 20220101), - geo_values = "*") |> + geo_values = "*" +) |> select(geo_value, time_value, death_rate = value) cases_deaths <- full_join(cases, deaths, by = c("time_value", "geo_value")) |> @@ -156,7 +160,7 @@ First, to eliminate some of the noise coming from daily reporting, we do 7 day a ```{r smooth} cases_deaths <- - cases_deaths |> + cases_deaths |> group_by(geo_value) |> epi_slide( cases_7dav = mean(case_rate, na.rm = TRUE), @@ -181,7 +185,8 @@ cases_deaths <- ungroup() |> mutate( death_rate = outlr_death_rate_replacement, - case_rate = outlr_case_rate_replacement) |> + case_rate = outlr_case_rate_replacement + ) |> select(geo_value, time_value, case_rate, death_rate) cases_deaths ``` @@ -196,8 +201,8 @@ of the states, noting the actual forecast date: forecast_date_label <- tibble( geo_value = rep(plot_locations, 2), - source = c(rep("case_rate",4), rep("death_rate", 4)), - dates = rep(forecast_date - 7*2, 2 * length(plot_locations)), + source = c(rep("case_rate", 4), rep("death_rate", 4)), + dates = rep(forecast_date - 7 * 2, 2 * length(plot_locations)), heights = c(rep(150, 4), rep(1.0, 4)) ) processed_data_plot <- @@ -209,7 +214,8 @@ processed_data_plot <- facet_grid(source ~ geo_value, scale = "free") + geom_vline(aes(xintercept = forecast_date)) + geom_text( - data = forecast_date_label, aes(x=dates, label = "forecast\ndate", y = heights), size = 3, hjust = "right") + + data = forecast_date_label, aes(x = dates, label = "forecast\ndate", y = heights), size = 3, hjust = "right" + ) + scale_x_date(date_breaks = "3 months", date_labels = "%Y %b") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) ``` @@ -260,7 +266,8 @@ narrow_data_plot <- facet_grid(source ~ geo_value, scale = "free") + geom_vline(aes(xintercept = forecast_date)) + geom_text( - data = forecast_date_label, aes(x=dates, label = "forecast\ndate", y = heights), size = 3, hjust = "right") + + data = forecast_date_label, aes(x = dates, label = "forecast\ndate", y = heights), size = 3, hjust = "right" + ) + scale_x_date(date_breaks = "3 months", date_labels = "%Y %b") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) ``` @@ -278,7 +285,8 @@ forecast_plot <- epipredict:::plot_bands( restricted_predictions, levels = 0.9, - fill = primary) + + fill = primary + ) + geom_point(data = restricted_predictions, aes(y = .data$value), color = secondary) ```