View source: R/get_genstate_covid.R
get_genstate_covid | R Documentation |
Pulls data from the CDC on COVID cases and deaths for a state and then merges alongside a population number from the 2020 Census population estimates for that state to use for rate calculation.
get_genstate_covid()
a data frame with the following columns: State, Date, General.Confirmed, General.Deaths, General.Population
get_genstate_covid() ## Not run: state_ <- "Georgia" # get state level covid data st_gen_df <- get_genstate_covid() %>% filter(State == state_) # get our prison data hist_df <- alt_aggregate_counts(all_dates = T) # get our prison denominators pri_pop <- read_aggregate_pop_data() %>% filter(State == state_) %>% pull(Residents.Population) %>% first() # calculate new cases for the state of interest hist_df %>% filter(Measure == "Residents.Confirmed" & State == state_) %>% filter(Web.Group == "Prison") %>% select(Date, Residents.Confirmed = Val) %>% mutate(Residents.New = diff_roll_sum(Residents.Confirmed, Date)) %>% mutate(Residents.Population = pri_pop) %>% # calculate the rate using latest denominators mutate(Residents = Residents.New/Residents.Population) %>% select(Date, Residents) %>% # join with the overall state data right_join( st_gen_df %>% mutate(General.New = diff_roll_sum(General.Confirmed, Date)) %>% mutate(General = General.New/General.Population) %>% select(Date, General)) %>% # pivot to make plotting easier pivot_longer(-Date, names_to = "Group", values_to = "CR") %>% filter(!is.na(CR)) %>% mutate(Group = ifelse( Group == "General", state_, str_c(state_, " DOC"))) %>% mutate(Group = fct_rev(Group)) %>% filter(Date >= lubridate::ymd("2021-01-01")) %>% ggplot(aes(x = Date, y = CR*100000, color = Group)) + geom_line(size = 2) + theme_behindbars() + scale_color_bbdiscrete() + labs(y = "New Case Rate\nPer100,000", color = "") + theme(legend.position = c(.38, .92)) + theme(legend.background = element_rect(fill = "transparent")) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.