suppressPackageStartupMessages({
library(covdata)
library(dplyr)
library(ggplot2)
library(geofacet)
library(glue)
})
pop_state <- uspop %>%
filter(sex_id == "totsex" & hisp_id == "tothisp") %>%
group_by(region_name, state_abbreviation = state_abbr) %>%
summarize(pop = sum(pop), .groups = "drop")
deaths_state_week <- nchs_wdc %>%
group_by(state_abbreviation, year, week, week_ending_date) %>%
summarize(deaths = sum(number_of_deaths), .groups = "drop") %>%
inner_join(pop_state, by = "state_abbreviation") %>%
mutate(
deaths_per_100k = deaths / pop * 100000
)
max_2020data_week <- deaths_state_week %>%
filter(year == 2020) %>%
group_by(state_abbreviation) %>%
filter(week == max(week)) %>%
ungroup() %>%
filter(week %in% range(week)) %>%
arrange(week) %>%
pull(week_ending_date) %>%
unique() %>%
paste(collapse = " - ")
ggplot(
deaths_state_week,
aes(x = week, y = deaths_per_100k, color = year == 2020, alpha = year == 2020, group = year)
) + geom_line() +
scale_color_manual(values = c("black", "red"), guide = NULL) +
scale_alpha_manual(values = c(0.4, 1), guide = NULL) +
scale_x_continuous(name = "", breaks = NULL, ) +
scale_y_continuous(name = "") +
facet_geo(~state_abbreviation) +
labs(
title = "Deaths per 100k residents by state: 2020 compared to 2015-2019",
subtitle = glue("2020 data through {max_2020data_week} (and are provisional so may be updated)"),
caption = glue(
"Data from National Center for Health Statistics via Kieran Healy's covdata package\n",
"https://kjhealy.github.io/covdata/"
)
)