Skip to content

Instantly share code, notes, and snippets.

@jbr
Last active March 29, 2020 00:17
Show Gist options
  • Save jbr/928caa9d37af66f85ee83c86438218b7 to your computer and use it in GitHub Desktop.
Save jbr/928caa9d37af66f85ee83c86438218b7 to your computer and use it in GitHub Desktop.
covid data per capita
library(choroplethr)
library(tidyverse)
library(choroplethrMaps)
data(county.regions)
data(df_pop_county)
data <-
"https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv" %>%
url() %>%
read.csv(stringsAsFactors = FALSE) %>%
as_tibble() %>%
rename(region = fips) %>%
group_by(region) %>%
summarise(cases = max(cases), deaths = max(deaths)) %>%
right_join(county.regions) %>%
full_join(df_pop_county) %>%
rename(pop = value) %>%
replace_na(list(deaths = 0, cases = 0)) %>%
mutate(full.name = paste(county.name, ", ", state.abb, sep = ""))
data %>%
mutate(value = 1000000 * cases / pop) %>%
county_choropleth(
title = "COVID-19 cases per million (3/28/20 nyt data and 2010 census)",
legend = "cases per million",
num_colors = 1,
state_zoom = c("california", "oregon", "washington")
)
#
# data %>%
# filter(deaths > 0) %>%
# ggplot(aes(x=1000000*deaths/pop, y=1000000*cases/pop, label=full.name, color=pop)) + scale_color_continuous(trans="log") + scale_x_log10()+ scale_y_log10()+ geom_text(size = I(2)) + xlab("deaths per million") + ylab("cases per million")
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment