Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Last active May 8, 2022 09:04
Show Gist options
  • Save MJacobs1985/da4387f8ec0849c4d546c2e1b2d39497 to your computer and use it in GitHub Desktop.
Save MJacobs1985/da4387f8ec0849c4d546c2e1b2d39497 to your computer and use it in GitHub Desktop.
rm(list = ls())
require(dplyr)
require(ggplot2)
require(ISOweek)
require(scales)
library(readr)
library(timetk)
rivm.data <- read_csv("COVID-19_casus_landelijk_2020-07-01.csv")
rivm.death <- rivm.data %>%
dplyr::filter(Deceased == "Yes") ## Extract deaths data only
rivm.hospital <- rivm.data %>%
dplyr::filter(Hospital_admission == "Yes") ## Extract hospital data only
rivm.hospital$Date_statistics <- as.Date(rivm.hospital$Date_statistics)
hospital <- rivm.hospital %>%
filter(Date_statistics_type == "DOO") %>%
group_by(Date_statistics, Province) %>%
summarise(aantal_opnames = n())
hospital$aantal_opnames<-as.numeric(hospital$aantal_opnames)
str(hospital)
hospital<-as.data.frame(hospital)
str(hospital)
interventie <- data.frame(Province = unique(hospital$Province),
int = c(rep(as.Date("2020-03-16"),
times = length((unique(hospital$Province))))))
ggplot(hospital, aes(x=Date_statistics, y=aantal_opnames)) +
geom_line() +
facet_wrap(~ Province, scales="free") +
geom_vline(aes(xintercept = int), interventie, col="red", lty=2) +
theme(axis.text.x = element_text(angle = 90)) +
labs(x="Date", y="Hopsital Admision")+
theme_bw()
hospital%>%
group_by(Province)%>%
summarise_by_time(
.date_var = Date_statistics,
.by = "week",
value = sum(aantal_opnames))%>%
mutate(deriv = value-lag(value),
deriv2 = deriv - lag(deriv))%>%
ggplot(., aes(x=Date_statistics)) +
geom_line(aes(y=value, colour="Hospital Admission")) +
geom_line(aes(y=deriv, colour="First derivative"))+
geom_line(aes(y=deriv2, colour="Second derivative"))+
facet_wrap(~ Province, scales="free_y") +
theme(axis.text.x = element_text(angle = 90)) +
scale_colour_manual(name="Legend",
values=c('seagreen','grey','darkred'),
labels = c("Hospital Admission",
"First derivative",
"Second derivative"))+
geom_point(aes(y=value), color="black", size=1.5)+
geom_point(aes(y=deriv), color="green", size=1.5)+
geom_point(aes(y=deriv2), color="red", size=1.5)+
geom_vline(aes(xintercept = int), interventie, col="purple", lty=2) +
labs(x="Date",
y="Hopsital Admision",
title="Hospital Admisions prior and following first lockdown")+
theme_bw()+
theme(legend.position="bottom")
hospital%>%
group_by(Province)%>%
summarise_by_time(
.date_var = Date_statistics,
.by = "week",
value = sum(aantal_opnames))%>%
mutate(deriv = value-lag(value),
deriv2 = deriv - lag(deriv))%>%
ggplot(., aes(x=Date_statistics)) +
geom_line(aes(y=value, colour=Province)) +
geom_point(aes(y=value, colour=Province), size=1.5) +
theme(axis.text.x = element_text(angle = 90)) +
geom_vline(aes(xintercept = int), interventie, col="black", lty=2) +
labs(x="Date",
y="Infections",
title="Infections prior and following first lockdown")+
theme_bw()+
theme(legend.position="bottom")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment