Skip to content

Instantly share code, notes, and snippets.

@slodge
Last active January 25, 2021 09:54
Show Gist options
  • Save slodge/f6e5c5b43e6d2bf5fbe2d812334016e0 to your computer and use it in GitHub Desktop.
Save slodge/f6e5c5b43e6d2bf5fbe2d812334016e0 to your computer and use it in GitHub Desktop.
resp <- httr::GET("https://api.coronavirus.data.gov.uk/v2/data?areaType=nation&metric=newTestsByPublishDate&metric=newCasesByPublishDate&format=json")
text <- httr::content(resp, as="text")
json <- jsonlite::fromJSON(text)
stats <- json$body %>% tibble::as_tibble()
to_plot <- stats %>%
mutate(date = as.Date(date)) %>%
filter(date >= "2020-09-01") %>%
group_by(areaName) %>%
arrange(date) %>%
mutate(
daily_test = newTestsByPublishDate,
daily_cases = newCasesByPublishDate,
daily_rate = 100 * daily_cases / daily_test,
sevenDayChange = daily_rate - lag(daily_rate, 7)
)
ggplot(to_plot) + geom_smooth(aes(date, sevenDayChange, color=areaName)) + geom_hline(yintercept=0) + facet_wrap(~areaName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment