Compilation date: 01.12.2020
library(ggplot2)
library(cowplot)
library(magrittr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
here_r = function (...) here::here("Statistics", "R", ...)
here_koco = function (...) here::here("KoCo19_Datasets", ...)
here_out = function (...) here::here("Epi_out", "epi_figures_yannik", ...)
dir.create(here_out(), showWarnings = FALSE)
# Setup
source(here_r("setup.R"))
source(here_r("functions.R"))
# Definitions
col_red = "#bf635d"
col_blue = "#59a3b2"
col_green = "#59ab7c"
col_yellow = "#efae59"
col_koco = col_blue
col_muc = col_red
col_koco2 = "#01579B"
col_muc2 = "#B00020"
col_books = col_yellow
# Range of dates to consider for cases and deaths, and plotting
date_range = c(as.Date("2020-03-02"), as.Date("2020-06-12"))
# Plotting break points and labels
date_breaks = as.Date(
c("2020-03-01", "2020-04-01", "2020-05-01", "2020-06-01"))
date_break_labels =
c("01.03.", "01.04.", "01.05.", "01.06.")
###############################################################################
# Set up Munich data
# Read cases
muc_data_cases = read.csv(here_koco(
"Analysis Data Sets", "Altersverteilung_Neuinfizierte.csv"))
muc_data_cases$NewCasesGE14 = rowSums(
muc_data_cases[,c("X14_bis_34", "X35_bis_49", "X50_bis_64", "X65_bis_79",
"X80_plus")])
muc_data_cases$Date = as.Date(muc_data_cases$X, format="%Y-%m-%d")
muc_data_cases = muc_data_cases[,c("NewCasesGE14", "Date")]
# Read deaths
muc_data_deaths = read.csv(here_koco(
"Analysis Data Sets", "Altersverteilung_Todesfaelle.csv"))
muc_data_deaths$NewDeathsGE14 = rowSums(
muc_data_deaths[,c("X14_bis_34", "X35_bis_49", "X50_bis_64", "X65_bis_79",
"X80_plus")])
muc_data_deaths$Date = as.Date(muc_data_deaths$X, format="%Y-%m-%d")
muc_data_deaths = muc_data_deaths[,c("NewDeathsGE14", "Date")]
# Merge cases and deaths, insert NA where a value is missing (full join)
muc_data = full_join(muc_data_cases, muc_data_deaths, by = "Date")
# Add all days in between
muc_data = full_join(
muc_data,
data.frame(Date=seq(min(muc_data$Date), max(muc_data$Date), "days")),
by = "Date")
# Sort by date
muc_data = muc_data[order(muc_data$Date),]
# Missing values are no cases or deaths, fill with zeros
muc_data[is.na(muc_data)] = 0
# Get week
muc_data$Week = lubridate::isoweek(muc_data$Date)
# Restrict date range
muc_date = muc_data[muc_data$Date>=date_range[1] &
muc_data$Date<=date_range[2],]
# Group by week
muc_week = muc_date %>% group_by(Week) %>%
summarise(Date=min(Date),
NewCasesGE14=sum(NewCasesGE14),
NewDeathsGE14=sum(NewDeathsGE14))
## `summarise()` ungrouping output (override with `.groups` argument)
# Calculate cumulatives
muc_week$CumCasesGE14=cumsum(muc_week$NewCasesGE14)
muc_week$CumDeathsGE14=cumsum(muc_week$NewDeathsGE14)
###############################################################################
# Set up KoCo data
koco_data = read.csv(here_koco("Analysis Data Sets", "Koco_baseline.csv"))
koco_data$Result_bin = ifelse(koco_data$R_quant >= cutoff$new$Roche, 1, 0)
koco_data$Date = as.Date(koco_data$VisitDate, format = c("%Y-%m-%d"))
koco_data$Week = lubridate::isoweek(koco_data$Date)
# Sort by date
koco_data = koco_data[order(koco_data$Date),]
# Attach all week 24 to week 23 due to low case numbers thereafter
koco_data[koco_data$Week>23, "Date"] =
max(koco_data[koco_data$Week<=23, "Date"])
koco_data[koco_data$Week>23, "Week"] = 23
# Group per date (not used)
koco_date = koco_data %>% group_by(Date) %>%
summarise(NewRecruits=n(), NewCases=sum(Result_bin))
## `summarise()` ungrouping output (override with `.groups` argument)
koco_date$CumRecruits = cumsum(koco_date$NewRecruits)
koco_date$CumCases = cumsum(koco_date$NewCases)
# Group per week
koco_week = koco_data %>% group_by(Week) %>%
summarise(NewRecruits=n(), NewCases=sum(Result_bin), Date=min(Date))
## `summarise()` ungrouping output (override with `.groups` argument)
koco_week$CumRecruits = cumsum(koco_week$NewRecruits)
koco_week$CumCases = cumsum(koco_week$NewCases)
# Normalize
koco_week$NewCases_rel = koco_week$NewCases / koco_week$NewRecruits
# Uncertainties
koco_week[c("NewCases_rel_lci", "NewCases_rel_uci")] =
epitools::pois.exact(koco_week$NewCases, koco_week$NewRecruits,
conf.level = 0.95)[c("lower", "upper")]
# Get prevalence estimate with CI
here_weights = function (...) here::here("SamplingWeights", ...)
# Prevalence estimates
estimates <- read.csv(here_weights("All_estimates.csv"))
vals = estimates[(estimates$calculation=="weighted") &
(estimates$test=="Roche") &
(estimates$cut_off=="optimised") &
(estimates$adjustment=="optimised"),]
prev_adj_wei_estimate = vals$estimate / 100
prev_adj_wei_lci = vals$lower_ci / 100
prev_adj_wei_uci = vals$upper_ci / 100
# Icons
here_images = function (...) here::here("Icons", ...)
icon_antibody = png::readPNG(here_images("icon_antibody.png"))
icon_coronavirus = png::readPNG(here_images("icon_coronavirus.png"))
icon_book = png::readPNG(here_images("icon_list.png"))
g_antibody = grid::rasterGrob(icon_antibody)
g_coronavirus = grid::rasterGrob(icon_coronavirus)
g_book = grid::rasterGrob(icon_book)
ggplot() + annotation_custom(g_antibody)
ggplot() + annotation_custom(g_coronavirus)
ggplot() + annotation_custom(g_book)
plt_muc_weeklycumu = ggplot(data=muc_week, aes(x=Date, y=CumCasesGE14)) +
geom_line(col=col_muc) + geom_point(col=col_muc) +
scale_x_date(
limits = date_range, breaks=date_breaks, labels = date_break_labels) +
theme(axis.title.x = element_blank()) +
labs(y="Cumulative # \nPCR positive tests", x="")
plt_muc_weeklycumu
ggsave(here_out("muc_weeklycumu.png"), width=3.5, height=2.5, dpi=720)
ggsave(here_out("muc_weeklycumu.pdf"), width=3.5, height=2.5, dpi=720)
# Just for checking
ggplot(data=koco_week, aes(x=Date, y=CumRecruits)) +
geom_line(col=col_koco) + geom_point(col=col_koco)
ggplot(data=koco_week, aes(x=Date, y=CumCases)) +
geom_line(col=col_koco) + geom_point(col=col_koco)
#ggplot(data=koco_date, aes(x=Date, y=Cases_rel)) +
# geom_line(col=col_koco) + geom_point(col=col_koco)
plt_koco_weeklyfrac = ggplot(data=koco_week, aes(x=Date, y=NewCases_rel)) +
geom_rect(
ymin=prev_adj_wei_lci, ymax=prev_adj_wei_uci,
xmin=min(koco_week$Date), xmax=max(koco_week$Date),
fill="grey90") +
geom_segment(
y = prev_adj_wei_estimate, yend = prev_adj_wei_estimate,
x=min(koco_week$Date), xend=max(koco_week$Date)) +
geom_line(col=col_koco) + geom_point(col=col_koco) +
geom_line(aes(y=NewCases_rel_lci), col=col_koco, linetype="dashed") +
geom_line(aes(y=NewCases_rel_uci), col=col_koco, linetype="dashed") +
scale_y_continuous(
limits = c(0, max(koco_week$NewCases_rel_uci)), labels = scales::percent) +
#scale_x_date(limits = date_range, labels = scales::date_format("%b %d"))
scale_x_date(
limits = date_range, breaks=date_breaks, labels = date_break_labels) +
theme(axis.title.x = element_blank()) +
labs(y="Percentage positive\nantibody tests", x="")
plt_koco_weeklyfrac
ggsave(here_out("koco_weeklyfrac.png"), width=3.5, height=2.5, dpi=720)
ggsave(here_out("koco_weeklyfrac.pdf"), width=3.5, height=2.5, dpi=720,
device=cairo_pdf)
plt_muc_weeklycases = ggplot(data=muc_week, aes(x=Date, y=NewCasesGE14)) +
geom_line(col=col_muc) + geom_point(col=col_muc) +
#scale_x_date(limits = date_range, labels = scales::date_format("%b %d"))
scale_x_date(limits = date_range, breaks=date_breaks,
labels = date_break_labels) +
theme(axis.title.x = element_blank()) +
labs(y="# officially registered\nPCR positive tests per week", x="")
plt_muc_weeklycases
ggsave(here_out("muc_weeklycases.png"), width=3.5, height=2.5, dpi=720)
ggsave(here_out("muc_weeklycases.pdf"), width=3.5, height=2.5, dpi=720)
plt_koco_weeklyrecruits = ggplot(data=koco_week, aes(x=Date, y=NewRecruits)) +
geom_line(col=col_koco) + geom_point(col=col_koco) +
#scale_x_date(limits = date_range, labels = scales::date_format("%b %d"))
scale_x_date(limits = date_range, breaks=date_breaks,
labels = date_break_labels) +
scale_y_continuous(limits = c(0, max(koco_week$NewRecruits))) +
theme(axis.title.x = element_blank()) +
labs(y="# KoCo19 participants\nper week", x="")
plt_koco_weeklyrecruits
ggsave(here_out("koco_weeklyrecruits.png"), width=3.5, height=2.5, dpi=720)
ggsave(here_out("koco_weeklyrecruits.pdf"), width=3.5, height=2.5, dpi=720)
# Just for checking
ggplot(data=koco_week, aes(x=Date, y=NewCases)) +
geom_line(col=col_koco) + geom_point(col=col_koco)
# Munich population size
muc_pop_size = 1369444 # 1561720
# From the Munich data, we take the case count on the last day (June 12)
total_cases = sum(muc_week$NewCasesGE14)
muc_estimate = total_cases / muc_pop_size
cat("Official prevalence:", total_cases, "/", muc_pop_size,
"=", muc_estimate, "\n")
## Official prevalence: 6293 / 1369444 = 0.004595296
cat("KoCo19 prevalence estimate:", prev_adj_wei_estimate, "\n")
## KoCo19 prevalence estimate: 0.01824793
rounded_labels <- function(x) sprintf("%.1f%%", x*100)
plt_prevalence = ggplot(
data.frame(Source=factor(c("Official", "KoCo19"),
levels=c("Official", "KoCo19")),
Prevalence=c(muc_estimate, prev_adj_wei_estimate),
Image=c(here_images("icon_coronavirus.png"),
here_images("icon_antibody.png"))),
aes(x=Source, y=Prevalence, col=Source, fill=Source)) +
geom_bar(stat="identity", alpha=0.5) +
scale_color_manual(values=c(col_muc, col_koco)) +
scale_fill_manual(values=c(col_muc, col_koco)) +
theme(legend.position = "none", axis.title.x=element_blank()) +
annotation_custom(g_coronavirus, xmin=0.8, xmax=1.2, ymin=0.0184, ymax=Inf) +
annotation_custom(g_antibody, xmin=1.8, xmax=2.2, ymin=0.0184, ymax=Inf) +
geom_segment(
x = 1.1, y = muc_estimate+0.0003,
xend = 1.1, yend = prev_adj_wei_estimate-0.0003,
lineend = "round", linejoin = "round",
arrow = arrow(length = unit(0.08, "npc")),
colour = "grey40") +
geom_segment(
xend = 1.1, yend = muc_estimate+0.0003,
x = 1.1, y = prev_adj_wei_estimate-0.0003,
lineend = "round", linejoin = "round",
arrow = arrow(length = unit(0.08, "npc")),
colour = "grey40") +
annotate(geom="text", x= 0.9,
y=muc_estimate + (prev_adj_wei_estimate - muc_estimate) / 2,
label=sprintf(
"≈ %.0f times", prev_adj_wei_estimate / muc_estimate),
angle=90) +
scale_y_continuous(limits=c(0,0.0204), labels=rounded_labels) +
labs(x="", y="Prevalence estimate")
plt_prevalence
ggsave(here_out("prevalence.png"), width=2.5, height=3.5, dpi=720)
ggsave(here_out("prevalence.pdf"), width=2.5, height=3.5, dpi=720,
device=cairo_pdf)
here_weights = function (...) here::here("SamplingWeights", ...)
# Prevalence estimates
estimates = read.csv(here_weights("All_estimates.csv"))
# Number of estimated cases
nb_est_cases = muc_pop_size * estimates[
estimates$test == "Roche" & estimates$calculation == "weighted" &
estimates$cut_off == "optimised" & estimates$adjustment == "optimised",
c("estimate", "lower_ci", "upper_ci")] / 100
# Number of officially registered cases
n_cases = 6293
# Number of reported cases in private households ranging
# from 1259 (20%) to 6293 (100%)
data_pcr = data.frame(
nb_rep_cases = seq(n_cases*0.2, n_cases, length.out=100))
data_pcr$pct_rep_cases = data_pcr$nb_rep_cases / n_cases * 100
data_pcr$estimate = nb_est_cases$estimate / data_pcr$nb_rep_cases
data_pcr$lower_ci = nb_est_cases$lower_ci / data_pcr$nb_rep_cases
data_pcr$upper_ci = nb_est_cases$upper_ci / data_pcr$nb_rep_cases
# RKI: 87.3361932% of reported cases in private households
pct_rki_cases = 87.3361932
under_rep_fact_rki = nb_est_cases / (n_cases * pct_rki_cases / 100)
# 100 privates
pct_100_cases = 100
under_rep_fact_100 = nb_est_cases / n_cases
col_rki = "grey40"
add_big_annotation = function (plt, pct, under_rep, label, x, y) {
plt +
# Type label
geom_text(data=onesie,
x=pct, y=y, label=label, size=3, color=col_rki, hjust=0.6) +
# horizontal line
geom_segment(data=onesie,
aes(x=x+6, y=under_rep$estimate,
xend=pct, yend=under_rep$estimate),
linetype="dotted", color=col_rki) +
# vertical line
geom_segment(data=onesie,
aes(x=pct, xend=pct,
y=under_rep$estimate, yend=y-1),
linetype="dotted", color=col_rki) +
# numbers
geom_text(data=onesie, x=x, y=under_rep$estimate, size=3,
color=col_rki, hjust=0.5, vjust=-0.05,
label=sprintf("%.1f", under_rep$estimate)) +
geom_text(data=onesie, x=x, y=under_rep$estimate, size=3,
color=col_rki, hjust=0.5, vjust=1.05,
label=sprintf("[%.1f; %.1f]",
under_rep$lower_ci, under_rep$upper_ci))
}
# Dummy data for drawing things only once
onesie = data.frame(hohoho=1)
plt_hidden = ggplot(data=data_pcr, mapping=aes(x=pct_rep_cases)) +
# CI area
geom_ribbon(aes(ymin=lower_ci, ymax=upper_ci), fill="grey90") +
# Estimate curve
geom_line(aes(y=estimate)) +
# y axis limits
#scale_y_continuous(limits=c(1, max(data_pcr$upper_ci)+1)) +
# Labels
labs(x="Cases in private households [%]", y="Underreporting factor")
plt_hidden = add_big_annotation(
plt_hidden, pct_rki_cases, under_rep_fact_rki,
sprintf("RKI: %.0f%%", pct_rki_cases), 30, 12)
plt_hidden = add_big_annotation(
plt_hidden, pct_100_cases, under_rep_fact_100, "100%", 45, 10)
plt_hidden
# Reference number of deaths
n_deaths = 216
# Number of deaths in private households ranging from 43 (20%) to 216 (100%)
data_deaths = data.frame(
nb_rep_deaths = seq(n_deaths*0.2, n_deaths, length.out = 100))
data_deaths$pct_rep_deaths = data_deaths$nb_rep_deaths/n_deaths*100
data_deaths$estimate = data_deaths$nb_rep_deaths / nb_est_cases$estimate * 100
data_deaths$upper_ci = data_deaths$nb_rep_deaths / nb_est_cases$lower_ci * 100
data_deaths$lower_ci = data_deaths$nb_rep_deaths / nb_est_cases$upper_ci * 100
add_big_annotation = function (plt, pct, estimates, label, x, y) {
plt +
# RKI values
geom_text(data=onesie,
x=pct, y=y, label=label, size=3, color=col_rki, hjust=0.6) +
# horizontal line
geom_segment(data=onesie,
aes(x=pct, xend=x+8,
y=estimates$estimate, yend=estimates$estimate),
linetype="dotted", color=col_rki) +
# vertical line
geom_segment(data=onesie,
aes(x=pct, xend=pct,
y=estimates$estimate, yend=y+0.05),
linetype="dotted", color=col_rki) +
# numbers
geom_text(data=onesie, x=x, y=estimates$estimate, size=3,
color=col_rki, hjust=0.5, vjust=-0.05,
label=sprintf("%.2f%%", estimates$estimate)) +
geom_text(data=onesie, x=x, y=estimates$estimate, size=3,
color=col_rki, hjust=0.5, vjust=1.05,
label=sprintf(
"[%.2f; %.2f]",estimates$upper_ci, estimates$lower_ci))
}
# RKI: 53.9184112% of deaths in private households
pct_rki_deaths = 53.9184112
IFR_rki = (n_deaths*pct_rki_deaths/100) / nb_est_cases * 100
# 100% privates
IFR_100 = n_deaths / nb_est_cases * 100
plt_ifr = ggplot(data=data_deaths, mapping=aes(x=pct_rep_deaths)) +
# CI area
geom_ribbon(aes(ymin=lower_ci, ymax=upper_ci), fill="grey90") +
# Estimate curve
geom_line(aes(y=estimate)) +
labs(x="Deaths in private households [%]", y="Infection fatality ratio [%]")
plt_ifr = add_big_annotation(
plt_ifr, pct_rki_deaths, IFR_rki,
sprintf("RKI: %.0f%%", pct_rki_deaths), 26, 0.14)
plt_ifr = add_big_annotation(plt_ifr, 100, IFR_100, "100%", 26, 0.14)
plt_ifr
# Margin
mg=0.3
plt_1 = plot_grid(
plot_grid(
plot_grid(
ggplot() + annotation_custom(g_coronavirus) + theme_minimal(),
title_plot("A", plt_muc_weeklycases) +
theme(plot.margin = unit(c(mg,mg,mg,mg), "cm")),
title_plot("B", plt_muc_weeklycumu) +
theme(plot.margin = unit(c(mg,mg,mg,mg), "cm")),
nrow = 1, rel_widths = c(1.2, 5, 5)),
plot_grid(
ggplot() + annotation_custom(g_antibody) + theme_minimal(),
title_plot("C", plt_koco_weeklyrecruits) +
theme(plot.margin = unit(c(mg,mg,mg,mg), "cm")),
title_plot("D", plt_koco_weeklyfrac) +
theme(plot.margin = unit(c(mg,mg,mg,mg), "cm")),
nrow = 1, rel_widths = c(1.2, 5, 5)),
nrow=2),
plot_grid(
NULL,
title_plot("E", plt_prevalence) +
theme(plot.margin = unit(c(mg,mg,mg,mg), "cm")),
NULL, rel_heights = c(1, 5, 1), ncol = 1),
nrow=1, rel_widths = c(4, 1.2)
)
plt_1
ggsave(here_out("Fig_simple_cases.png"), width=10, height=5, dpi=720)
ggsave(here_out("Fig_simple_cases.pdf"), width=10, height=5, dpi=720,
device=cairo_pdf)
mort_data = read.csv(here_koco("Analysis Data Sets", "mor_muc.csv"))
mort_data$Mean = rowMeans(
mort_data[,c("Y2016", "Y2017", "Y2018", "Y2019")])
mort_data = mort_data %>% dplyr::rename(
"Week"="X", "2016"="Y2016", "2017"="Y2017", "2018"="Y2018", "2019"="Y2019",
"2020"="Y2020")
mort_data$Mean_2016_20 = NULL
# Restrict weeks to beginning of June
mort_data = mort_data[mort_data$Week < 25,]
# Add dates to mort_data and sub-select dates
mort_data = inner_join(
mort_data, muc_week[,c("Date" ,"Week", "NewDeathsGE14")], by = "Week")
# Calculate excess mortalities
mort_data$Excess2016 = mort_data$`2016`- mort_data$`Mean`
mort_data$Excess2017 = mort_data$`2017`- mort_data$`Mean`
mort_data$Excess2018 = mort_data$`2018`- mort_data$`Mean`
mort_data$Excess2019 = mort_data$`2019`- mort_data$`Mean`
mort_data$Excess2020 = mort_data$`2020`- mort_data$`Mean`
# To long format for figure
mort_data_long = mort_data %>%
reshape2::melt(
id=c("Week", "Date", "Excess2016", "Excess2017", "Excess2018",
"Excess2019", "Excess2020", "NewDeathsGE14")) %>%
dplyr::rename("Year"="variable")
# For correct order
mort_data_long$Year = factor(
mort_data_long$Year,
levels = c("2016", "2017", "2018", "2019", "Mean", "2020"))
plt_deaths = ggplot(mort_data_long,
aes(x=Date, col=`Year`, fill=`Year`, y=value)) +
geom_line() + geom_point() +
scale_y_continuous(limits=c(0, max(mort_data_long$value)+2)) +
scale_x_date(limits = date_range, breaks=date_breaks,
labels = date_break_labels) +
scale_color_manual(
values = c("grey65", "grey50", "grey35", "grey20",
col_green, col_yellow)) +
labs(x="", y="Deaths per week") +
theme(legend.title=element_blank(),
legend.position=c(0.5, 0.3),
legend.direction = "horizontal",
axis.title.x = element_blank())
plt_deaths
ggsave(here_out("deaths.png"), width=3.5, height=3, dpi=720)
ggsave(here_out("deaths.pdf"), width=3.5, height=3, dpi=720,
device=cairo_pdf)
# In this plot, we cut off values after week 23, as there were count
# corrections at the end of week 23
# To long format for figure
mort_data_long = mort_data[,
c("Date", "Excess2020", "NewDeathsGE14")] %>%
dplyr::rename("Excess mortality\nMarch-June 2020"="Excess2020",
"SARS-CoV-2\nassociated deaths"="NewDeathsGE14") %>%
reshape2::melt(id="Date") %>%
dplyr::rename("Year"="variable")
plt_excess = ggplot(mort_data_long, aes(x=Date, col=`Year`, fill=`Year`,
y=value)) +
geom_line() + geom_point() +
geom_area(
alpha=0.3, position="identity", show.legend = FALSE) +
geom_line() + geom_point() +
scale_x_date(limits = date_range, breaks=date_breaks,
labels = date_break_labels) +
scale_color_manual(values = c(col_books, col_muc)) +
scale_fill_manual(values = c(col_books, col_muc)) +
geom_hline(yintercept=0, linetype="dotted") +
scale_y_continuous(limits=c(-50,max(mort_data_long$value))) +
labs(x="", y="Deviations in the weekly\nnumber of deaths") +
theme(legend.title=element_blank(),
legend.position=c(0.5, 0.25),
legend.background = element_blank(),
# No other way to increase the spacing
legend.key.height=unit(0.8, 'cm'),
#legend.direction="vertical",
axis.title.x = element_blank())
plt_excess
ggsave(here_out("excess.png"), width=3.5, height=3, dpi=720)
ggsave(here_out("excess.pdf"), width=3.5, height=3, dpi=720,
device=cairo_pdf)
# Total excess mortalitiy in the period of consideration
total_excess_mortality = sum(mort_data$Excess2020)
cat("Excess mortality:", total_excess_mortality, "\n")
## Excess mortality: 186
# Total Covid related deaths in the period of consideration
# Has to be 210!
total_covid_deaths = sum(muc_week$NewDeathsGE14)
cat("SARS-CoV-2 associated deaths:", total_covid_deaths, "\n")
## SARS-CoV-2 associated deaths: 216
# Category labels
labels = c("Excess mortality\nMarch-June 2020",
"SARS-CoV-2\nassociated deaths")
plt_total_deaths = ggplot(
data.frame(Source=factor(labels, levels=labels),
Total=c(total_excess_mortality, total_covid_deaths),
Image=c(here_images("icon_book.png"),
here_images("icon_coronavirus.png"))),
aes(x=Source, y=Total, col=Source, fill=Source)) +
geom_bar(stat="identity", alpha=0.5) +
scale_color_manual(values=c(col_books, col_muc)) +
scale_fill_manual(values=c(col_books, col_muc)) +
scale_y_continuous(limits=c(0,252)) +
annotation_custom(g_book, xmin=0.8, xmax=1.2, ymin=223, ymax=Inf) +
annotation_custom(g_coronavirus, xmin=1.8, xmax=2.2, ymin=223, ymax=Inf) +
theme(legend.position = "none", axis.title.x=element_blank()) +
labs(x="", y="Total number of deaths")
plt_total_deaths
ggsave(here_out("total_deaths.png"), width=3.5, height=3, dpi=720)
ggsave(here_out("total_deaths.pdf"), width=3.5, height=3, dpi=720,
device=cairo_pdf)
plt_2= plot_grid(
title_plot("A", plt_deaths) +
theme(plot.margin = unit(c(mg,mg,mg,mg), "cm")),
title_plot("B", plt_excess) +
theme(plot.margin = unit(c(mg,mg,mg,mg), "cm")),
title_plot("C", plt_total_deaths) +
theme(plot.margin = unit(c(mg,mg,mg,mg), "cm")),
nrow = 1, rel_widths = c(4, 4, 4)
)
plt_2
ggsave(here_out("Fig_simple_deaths.png"), width=10, height=3, dpi=720)
ggsave(here_out("Fig_simple_deaths.pdf"), width=10, height=3, dpi=720,
device=cairo_pdf)
mg=0.5
library(patchwork)
##
## Attaching package: 'patchwork'
## The following object is masked from 'package:cowplot':
##
## align_plots
plt1 =
ggdraw() + draw_label(
"Virus vs. antibody positivity", x=0, hjust=0, fontface="bold") +
ggplot() + annotation_custom(g_coronavirus) + theme_minimal() +
plt_muc_weeklycases + labs(tag = "A") +
plt_muc_weeklycumu + labs(tag = "B") +
plt_hidden + labs(tag = "C") +
ggplot() + annotation_custom(g_antibody) + theme_minimal() +
plt_koco_weeklyrecruits + labs(tag = "D") +
plt_koco_weeklyfrac + labs(tag = "E") +
plt_ifr + labs(tag = "F") +
ggdraw() + draw_label(
"Excess mortality vs. SARS-CoV-2 associated deaths", x=0, hjust=0,
fontface="bold") +
ggplot() + annotation_custom(g_book) + theme_minimal() +
plt_deaths + labs(tag = "G") + plt_excess + labs(tag = "H") +
plt_total_deaths + labs(tag = "I") +
plot_layout(widths = c(0.5, 5, 5, 5),
heights = c(0.2, 1, 1, 0.2, 1),
design = "#AAA\nBCDE\nFGHI\n#JJJ\nKLMN")
#design = "AAAA\nBCD#\nBCDH\nEFGH\nEFG#\n####\nIIII\nJKLM")
plt1
#ggsave(here_out("Fig_simple_cases_and_deaths.png"),
# width=12, height=7.5, dpi=400)
#ggsave(here_out("Fig_simple_cases_and_deaths.pdf"),
# width=12, height=7.5, dpi=720, device=cairo_pdf)
mg=0.5
library(patchwork)
plt1 =
ggdraw() + draw_label(
"Virus vs. antibody positivity", x=0, hjust=0) +
ggplot() + annotation_custom(g_coronavirus) + theme_minimal() +
ggplot() + annotation_custom(g_antibody) + theme_minimal() +
plt_muc_weeklycases + labs(tag = "A") +
plt_koco_weeklyrecruits + labs(tag = "B") +
plt_hidden + labs(tag = "C") +
plt_muc_weeklycumu + labs(tag = "D") +
plt_koco_weeklyfrac + labs(tag = "E") +
plt_ifr + labs(tag = "F") +
ggdraw() + draw_label(
"Excess mortality vs. SARS-CoV-2 associated deaths", x=0, hjust=0) +
plt_deaths + labs(tag = "G") +
plt_excess + labs(tag = "H") +
plt_total_deaths + labs(tag = "I") +
plot_layout(widths = c(5, 5, 5),
heights = c(0.2, 0.15, 1, 1, 0.2, 1),
design = "AAA\nBC#\nDEF\nGHI\nJJJ\nKLM")
#design = "AAAA\nBCD#\nBCDH\nEFGH\nEFG#\n####\nIIII\nJKLM")
plt1
ggsave(here_out("Fig_simple_cases_and_deaths.png"),
width=12, height=9, dpi=400)
ggsave(here_out("Fig_simple_cases_and_deaths.pdf"),
width=12, height=9, dpi=720, device=cairo_pdf)