Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created December 3, 2021 23:36
Show Gist options
  • Select an option

  • Save MJacobs1985/41cd26770d1c7f05a6d127ad6205ada4 to your computer and use it in GitHub Desktop.

Select an option

Save MJacobs1985/41cd26770d1c7f05a6d127ad6205ada4 to your computer and use it in GitHub Desktop.
library(readr)
library(ggplot2)
library(gganimate)
library(tidyverse)
library(ggrepel)
library(lubridate)
library(tidymodels)
library(modeltime)
library(tsbox)
library(TSstudio)
library(timetk)
library(tseries)
coviddat <- read_csv("owid-covid-data (4).csv")
coviddat$vax_perc<-(coviddat$people_fully_vaccinated/coviddat$population)*100
coviddat$week<-week(coviddat$date)
coviddat2<-coviddat%>%dplyr::select(date,
week,
location,
continent,
vax_perc,
icu_patients_per_million,
stringency_index)%>%
filter(continent=="Europe")%>%
filter(complete.cases(.))%>%
group_by(location)%>%
summarise_by_time(date,.by="week",
vax_perc_week=max(vax_perc,na.rm=TRUE),
icu_week=max(icu_patients_per_million,na.rm=TRUE),
location=location,
continent=continent,
SI_week=mean(stringency_index,na.rm=TRUE))%>%distinct()
coviddat2$week<-week(coviddat2$date)
p<-coviddat2%>%filter(continent=="Europe" &
date>"2020-12-31")%>%ggplot(., aes(
x=vax_perc_week,
y=icu_week,
size = SI_week,
color=as.factor(location),
label=as.factor(location))) +
geom_text(nudge_y = 1) +
ylim(0,120) +
theme_bw() +
theme(legend.position = "none") +
labs(title= 'Week: {closest_state}',
x = 'Fully Vaxed Percentage',
y = 'ICU patients per Million') +
transition_states(week,
transition_length = 2,
state_length = 1) +
ease_aes('linear') +
enter_fade()+
exit_fade()
anim <- animate(p,nframes=3500, fps=35)
anim2 <- animate(p,nframes=350, fps=3)
anim3 <- animate(p,nframes=350, fps=15)
anim4 <- animate(p,nframes=350)
anim_save(filename="VAX_ICU.gif", animation=anim4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment