rate_plot <- ts_weekly |>
mutate(
roll_rate = slider::slide_index_dbl(
.x = rate,
.i = week,
.f = mean,
.before = 2,
.after = 2
)
) |>
ggplot(aes(x = week)) +
geom_line(aes(y = rate, color = "Raw weekly rate")) +
geom_line(aes(y = roll_rate, color = "4-week smoothed rate")) +
geom_segment(aes(color = "COVID",
x = ymd("2020-03-01"), xend = ymd("2020-03-01"),
y = 0, yend = 0.08)) +
scale_color_manual(
name = NULL,
breaks = c("Raw weekly rate", "4-week smoothed rate", "COVID"),
values = c("lightgray", "black", "#2c8c99")
) +
my_plot_styling()
rate_plot