Skip to content

Instantly share code, notes, and snippets.

@kathsherratt
Created September 30, 2021 11:21
Show Gist options
  • Save kathsherratt/1cd5aa7cd0c8c4b7789280db13c758d5 to your computer and use it in GitHub Desktop.
Save kathsherratt/1cd5aa7cd0c8c4b7789280db13c758d5 to your computer and use it in GitHub Desktop.
Plot hospitalisation data from Euro forecast hub
library(dplyr)
library(covidHubUtils)
library(ggplot2)
# Set up
min_date <- Sys.Date() - 6 * 7 # set an earliest date to display (eg six weeks)
location_names <- hub_locations_ecdc$location_name # set which countries to display (eg all countries with data)
# Get data
ecdc_daily <- load_truth(truth_source = "ECDC",
temporal_resolution = "daily",
local_repo_path = "here", hub = "ECDC")
ecdc_weekly <- load_truth(truth_source = "ECDC",
temporal_resolution = "weekly",
local_repo_path = "here", hub = "ECDC") %>%
rename(weekly_value = value)
ecdc <- left_join(ecdc_daily, ecdc_weekly) %>%
filter(location_name %in% location_names &
target_end_date > min_date)
# Plot
ecdc %>%
ggplot(aes(x = target_end_date)) +
# plot daily and weekly
geom_col(aes(y = value)) +
geom_point(aes(y = weekly_value)) +
#
facet_wrap(facets = "location_name",
scales = "free_y") +
labs(x = NULL, y = NULL,
subtitle = "Hub ECDC hospitalisations data",
caption = "daily (bars) and weekly (points) incident hospitalisations") +
theme_classic() +
theme(legend.position = "bottom",
strip.background = element_blank())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment