get_genstate_covid: Get general population state COVID data from CDC and Census...

View source: R/get_genstate_covid.R

get_genstate_covidR Documentation

Get general population state COVID data from CDC and Census 2020 pop estimates

Description

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.

Usage

get_genstate_covid()

Value

a data frame with the following columns: State, Date, General.Confirmed, General.Deaths, General.Population

Examples

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)


uclalawcovid19behindbars/behindbarstools documentation built on April 22, 2022, 4:08 a.m.