Skip to content

Instantly share code, notes, and snippets.

@gadenbuie
Created April 21, 2020 15:33
Show Gist options
  • Save gadenbuie/194f2994840f58c28a52bab6324033cc to your computer and use it in GitHub Desktop.
Save gadenbuie/194f2994840f58c28a52bab6324033cc to your computer and use it in GitHub Desktop.
library(tidyverse)

cvd_states <- read_csv(
  "https://covidtracking.com/api/v1/states/daily.csv",
  col_types = cols(
    .default = col_double(),
    date = col_date("%Y%m%d"),
    state = col_character(),
    hash = col_character(),
    dateChecked = col_datetime(format = ""),
    fips = col_character()
  )
)
cvd_states %>% 
  filter(positive >= 100) %>% 
  arrange(date) %>% 
  group_by(state) %>% 
  slice(1) %>% 
  ungroup() %>% 
  ggplot() +
  aes(date, y = 1) +
  geom_boxplot() +
  geom_jitter(aes(color = state, size = positive), height = 0.1) +
  guides(color = FALSE, size = FALSE) +
  labs(title = "Earliest Day Reporting ≥ 100 Positive COVID-19 Cases") +
  theme_minimal(18) +
  theme(
    axis.text.y = element_blank(),
    axis.title.y = element_blank(),
    axis.title.x = element_blank()
  )

cvd_states %>% 
  filter(death >= 10) %>% 
  arrange(date) %>% 
  group_by(state) %>% 
  summarize(date = min(date), death = max(death)) %>% 
  ungroup() %>% 
  ggplot() +
  aes(date, y = death) +
  geom_boxplot(y = 0, width = 1000, outlier.shape = NA) +
  geom_jitter(aes(color = state, size = death), height = 0.1) +
  guides(color = FALSE, size = FALSE) +
  labs(
    x = "Earliest Day Reporting ≥ 10 Deaths from COVID-19",
    y = str_wrap("Total Reported Deaths by April 20", 10)
  ) +
  theme_minimal(18) +
  theme(
    axis.title.y = element_text(angle = 0, hjust= 0),
  )

Created on 2020-04-21 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment