Last active
January 25, 2021 14:52
-
-
Save seabbs/1a2916e40ae7fac8f0eb7250dbfbef95 to your computer and use it in GitHub Desktop.
R code using {covid19.nhs.data} to generate a gif of Covid-19 hospital admissions byupper-tier local authority in England.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Packages ---------------------------------------------------------------- | |
library(covid19.nhs.data) | |
library(dplyr) | |
library(tidyr) | |
library(lubridate) | |
library(gganimate) | |
#devtools::install_github("thomasp85/transformr") | |
library(transformr) | |
library(gifski) | |
library(ggplot2) | |
# Get data ---------------------------------------------------------------- | |
adm <- get_admissions("utla") | |
shapefile <- england_utla_shape | |
# complete and filter from September | |
adm <- adm %>% | |
filter(date >= "2020-10-01") %>% | |
drop_na(date, geo_code, admissions) %>% | |
complete(geo_code, date, fill = list(admissions = 0)) | |
# Make map ---------------------------------------------------------------- | |
# map latest | |
map_admissions(adm, shapefile) + theme(legend.position = "right") | |
# map all time (for gif) | |
map <- adm %>% | |
mutate(date = factor(date)) %>% | |
map_admissions(shapefile, date = NULL) + | |
theme(legend.position = "right") | |
# Turn into a gif --------------------------------------------------------- | |
map <- map + | |
ggtitle('Date: {closest_state}') + | |
transition_states(date) | |
animate(map, fps = 5, nframes = length(unique(adm$date)) * 2, renderer = gifski_renderer()) | |
# Save gif ---------------------------------------------------------------- | |
anim_save("utla_admissions.gif") |
Author
seabbs
commented
Jan 25, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment