Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created February 16, 2022 08:29
Show Gist options
  • Select an option

  • Save MJacobs1985/6cbd4e6fa005ba6d00e4abbec4a26150 to your computer and use it in GitHub Desktop.

Select an option

Save MJacobs1985/6cbd4e6fa005ba6d00e4abbec4a26150 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)
getwd()
data_folder <- file.path("")
url <- "https://covid.ourworldindata.org/data/owid-covid-data.csv"
name <- "owid-covid-data.csv"
download.file(url = url, destfile = paste0(data_folder,name))
setwd(data_folder)
coviddat <- read_csv(paste0(data_folder,name))
coviddat$vax_perc<-(coviddat$people_fully_vaccinated/coviddat$population)*100
coviddat$week<-week(coviddat$date)
coviddat$year<-year(coviddat$date)
covidda
coviddat2<-coviddat%>%dplyr::select(date,
week,
year,
location,
continent,
vax_perc,
icu_patients_per_million,
excess_mortality,
stringency_index)%>%
filter(continent=="Europe")%>%
filter(complete.cases(.))%>%
group_by(location)%>%
summarise_by_time(date,.by=c("week","year"),
vax_perc_week=max(vax_perc,na.rm=TRUE),
icu_week=max(icu_patients_per_million,na.rm=TRUE),
location=location,
continent=continent,
em_week=mean(excess_mortality,na.rm=TRUE),
SI_week=mean(stringency_index,na.rm=TRUE))%>%distinct()
coviddat2$week<-week(coviddat2$date)
coviddat2$year<-year(coviddat2$date)
my.animation<-coviddat2%>%filter(continent=="Europe" &
date>"2020-12-31")%>%
ggplot(.)+
geom_line(aes(x=date,
y=em_week,
colour=as.factor(location)))+
geom_point(aes(x=date,
y=em_week,
colour=as.factor(location)), size=1)+
geom_dl(aes(x=date,
y=em_week,
label = location,
colour=as.factor(location)),
method = list(dl.combine("last.points")), cex = 0.8) +
theme_bw()+
theme(legend.position="none")+
labs(x="Date",
y="Excess Mortality",
title="Excess Mortality over Time by Country using OWID data",
col="Country")+
transition_reveal(date)
animate(my.animation, width=2000, height=1000,
res=150,
end_pause = 60,
nframes=300);anim_save("CovidEM.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment