get_genpop_covid: Get general population COVID data from NYT and Census 2019

View source: R/get_genpop_covid.R

get_genpop_covidR Documentation

Get general population COVID data from NYT and Census 2019

Description

Pulls data from the NYT github page on COVID cases and deaths for a county and then merges alongside a population number from the 2019 Census population estimates for that county to use for rate calculation.

Usage

get_genpop_covid(county, state = NULL)

Arguments

county

either a 5 digit fips code (safer) or a county name

state

a state name or abbreviation if a county name was provided

Value

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

Examples

## Not run: 
# get data from Orange county, North Carolina
get_genpop_covid(county = "Orange", state = "NC")
# get data from los angeles by fips code
get_genpop_covid(county = "06037")

get CA hist data
ca_df <- read_scrape_data(TRUE, state = "California")

# look only at SATF
satf_df <- ca_df %>%
    filter(Name == "SUBSTANCE ABUSE TREATMENT FACILITY")

# get the corresponding county data
county_df <- get_genpop_covid(first(satf_df$County.FIPS))

# make the plot comparing prison vs general population
county_df %>%
    # get rid of potential conflicting columns
    select(Date, tidyr::starts_with("General")) %>%
    right_join(satf_df) %>%
    mutate(`Prisoner\nPopulation` = Residents.Confirmed / Population.Feb20) %>%
    mutate(`King County\nPopulation` =
               General.Confirmed / General.Population2019) %>%
    select(Date, `Prisoner\nPopulation`, `King County\nPopulation`) %>%
    tidyr::pivot_longer(-Date) %>%
    mutate(name = forcats::fct_rev(name)) %>%
    ggplot(aes(x = Date, y = value, color = name, fill = name)) +
    geom_area(alpha=.5, size = 1.5, position = position_dodge()) +
    theme_behindbars() +
    scale_color_bbdiscrete() +
    labs(y = "Proportion\nInfected", color = "", fill = "") +
    ylim(c(0,.65)) +
    ggtitle(
        "Substance Abuse Treatment Facility Outbreak",
        "Comparing COVID Outbreaks in Prison and the Surrounding Area"
    )


## End(Not run)


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