Skip to content

Instantly share code, notes, and snippets.

@chasemc
Created May 14, 2020 14:04
Show Gist options
  • Save chasemc/6c46077244acbc61d7eded5ad94d3445 to your computer and use it in GitHub Desktop.
Save chasemc/6c46077244acbc61d7eded5ad94d3445 to your computer and use it in GitHub Desktop.
library(ggplot2)
library(data.table)
library(geofacet)
raw_data <- data.table::fread("http://covidtracking.com/api/states/daily.csv")
raw_data$date <- as.Date(as.character(raw_data$date), "%Y%m%d")
raw_data <- raw_data[date > "2020-03-15", ]
raw_data[ , corre := cor(totalTestResultsIncrease,positiveIncrease,
method = "spearman"), state]
raw_data[, maxHeight := max(totalTestResultsIncrease)*.75, state]
raw_data[, maxWidth := max(positiveIncrease)*.15, state]
ggplot(raw_data,aes(x = positiveIncrease, y=totalTestResultsIncrease)) +
geom_smooth(method="lm") +
geom_point(alpha = .2) +
geom_text(
aes(x=maxWidth,y=(maxHeight), label = round(corre,2))) +
facet_geo(~state,
grid = "us_state_grid1",
label = "name",
scales = "free")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment