diff --git a/Figures/Figure_1.pdf b/Figures/Figure_1.pdf index a17ed6f..91f717d 100644 Binary files a/Figures/Figure_1.pdf and b/Figures/Figure_1.pdf differ diff --git a/Figures/Figure_1.png b/Figures/Figure_1.png index 82f6b79..7a47b6d 100644 Binary files a/Figures/Figure_1.png and b/Figures/Figure_1.png differ diff --git a/Figures/Figure_2.pdf b/Figures/Figure_2.pdf index 3930095..1a28d7d 100644 Binary files a/Figures/Figure_2.pdf and b/Figures/Figure_2.pdf differ diff --git a/Figures/Figure_2.png b/Figures/Figure_2.png index 1f92092..e3e4896 100644 Binary files a/Figures/Figure_2.png and b/Figures/Figure_2.png differ diff --git a/Figures/Figure_3.pdf b/Figures/Figure_3.pdf index cbe6c02..ae0e6b1 100644 Binary files a/Figures/Figure_3.pdf and b/Figures/Figure_3.pdf differ diff --git a/Figures/Figure_3.png b/Figures/Figure_3.png index cd0a284..5e4d966 100644 Binary files a/Figures/Figure_3.png and b/Figures/Figure_3.png differ diff --git a/R/05_cumulative_excess_death_figures.R b/R/05_cumulative_excess_death_figures.R index beea656..70ce427 100644 --- a/R/05_cumulative_excess_death_figures.R +++ b/R/05_cumulative_excess_death_figures.R @@ -32,6 +32,7 @@ fig$figure1 <- results$excess.deaths.week.sex %>% filter(model == 'gam.nb') %>% ggplot() + + geom_hline(yintercept = 0) + geom_ribbon( aes( x = date, @@ -63,7 +64,7 @@ fig$figure1 <- filter(date == max(date)) ) + scale_x_date( - limits = as.Date(c('2020-03-01', '2020-12-01')), + limits = as.Date(c('2020-03-01', '2020-12-10')), date_breaks = '1 month', date_labels = '%b' ) + scale_y_continuous(labels = scales::label_comma()) + @@ -73,7 +74,11 @@ fig$figure1 <- x = NULL, y = 'Cumulative excess deaths' ) + - fig_spec$MyGGplotTheme(hgrid = TRUE, vgrid = TRUE, scaler = 1.3, show_legend = FALSE) + coord_cartesian(expand = FALSE, clip = 'off') + + fig_spec$MyGGplotTheme( + grid = 'xy', scaler = 1.3, show_legend = FALSE, + axis = 'none' + ) fig_spec$ExportPDF( fig$figure1, filename = 'Figure_1', path = 'Figures', @@ -91,6 +96,7 @@ fig$figure2 <- filter(model == 'gam.nb') %>% mutate(age.n = factor(age.n, cnst$age.labels, names(cnst$age.labels))) %>% ggplot() + + geom_hline(yintercept = 0) + geom_ribbon( aes( x = date, @@ -109,8 +115,8 @@ fig$figure2 <- ) + facet_wrap(~age.n) + scale_x_date( - limits = as.Date(c('2020-03-01', '2021-01-01')), - date_breaks = '2 months', + limits = as.Date(c('2020-03-01', '2020-12-31')), + date_breaks = '2 months', date_minor_breaks = '1 month', date_labels = '%b' ) + scale_y_continuous(labels = scales::label_comma()) + @@ -149,12 +155,11 @@ fig$figure2 <- group_by(sex, age.n) %>% filter(date == max(date)) ) + + coord_cartesian(expand = FALSE, clip = 'off') + fig_spec$MyGGplotTheme( - hgrid = TRUE, vgrid = TRUE, - scaler = 1.3, - show_legend = FALSE - ) + - coord_cartesian(clip = 'off') + grid = 'xy', minor_grid = 'x', scaler = 1.3, show_legend = FALSE, + axis = 'none' + ) fig_spec$ExportPDF( fig$figure2, filename = 'Figure_2', path = 'Figures', diff --git a/R/08_plot_life_expectancy.R b/R/08_plot_life_expectancy.R index b3e8614..fcf696c 100644 --- a/R/08_plot_life_expectancy.R +++ b/R/08_plot_life_expectancy.R @@ -35,7 +35,6 @@ fig$figure3 <- aes(x = year, y = ex, color = sex), size = 1 ) + - #scale_y_continuous(labels = scales::label_comma()) + scale_color_manual(values = c("#1E8B8F","#806152")) + scale_fill_manual(values = c("#1E8B8F","#806152")) + labs( @@ -47,7 +46,10 @@ fig$figure3 <- angle = c(30,38), color = c("#1E8B8F","#806152"), size = 6.5, hjust = 0, vjust = 1) + - fig_spec$MyGGplotTheme(hgrid = TRUE, scaler = 1.3, show_legend = FALSE) + fig_spec$MyGGplotTheme( + grid = 'xy', scaler = 1.3, show_legend = FALSE, + axis = 'x' + ) fig$figure4 <- fig.data %>% @@ -76,7 +78,10 @@ fig$figure4 <- x = NULL, y = NULL ) + - fig_spec$MyGGplotTheme(hgrid = TRUE, scaler = 1.3, show_legend = FALSE) + fig_spec$MyGGplotTheme( + grid = 'xy', scaler = 1.3, show_legend = FALSE, + axis = 'x' + ) library(patchwork) diff --git a/R/Figure_specifications.R b/R/Figure_specifications.R index 32e468d..d2d727e 100644 --- a/R/Figure_specifications.R +++ b/R/Figure_specifications.R @@ -1,125 +1,158 @@ -# figure specs -fig_spec <- list() - -# ggplot theme ---------------------------------------------------- - -# ggplot theme by Jonas Schöley -fig_spec$MyGGplotTheme <- - function ( - size = 8, - family = 'sans', - scaler = 1, - no_axes = FALSE, - panel_border = FALSE, - hgrid = FALSE, - vgrid = FALSE, - show_legend = TRUE, - ar = NA - ) { - - size_med = size*scaler - size_sml = round(size*0.7)*scaler - base_linesize = 0.3*scaler - - list( - theme_classic(base_size = size_med, base_family = family), - theme( - # basic - text = element_text(color = 'black'), - line = element_line(size = base_linesize, lineend = 'square'), - # axis - #axis.line.y = element_blank(), - axis.title = element_text(size = size_med, face = 'bold'), - axis.ticks = element_line(size = rel(0.5), color = 'black'), - axis.text = element_text(size = size_med, color = 'black'), - # strips - strip.text = element_text(color = 'black', size = size_med), - strip.background = element_blank(), - # plot - title = element_text(face = 'bold'), - plot.subtitle = element_text(color = 'black', size = size_med, face = 'bold'), - plot.caption = element_text(color = 'black', size = size_sml, face = 'plain'), - plot.background = element_blank(), - panel.background = element_blank(), - plot.margin = unit(c(1, 0.1, 0.5, 0.5), units = 'mm'), - ), - if (isTRUE(hgrid)) { - theme(panel.grid.major.y = - element_line(linetype = 3, color = 'grey80')) - }, - if (isTRUE(vgrid)) { - theme(panel.grid.major.x = - element_line(linetype = 3, color = 'grey80')) - }, - if (isTRUE(panel_border)) { - theme( - panel.border = - element_rect(fill = NA) - ) - }, - if (!isTRUE(show_legend)) { - theme(legend.position = 'none') - }, - if (isTRUE(no_axes)) { - theme( - axis.line = element_blank() - ) - }, - if (!is.na(ar)) { - theme( - aspect.ratio = ar - ) - } - ) - } - -# Dimensions ------------------------------------------------------ - -# figure width (mm) -fig_spec$width = 170 - -# Colors ---------------------------------------------------------- - -# color palette -fig_spec$discrete_colors <- - c('#D23737', # red - '#3191C9', # blue - '#D2BC2D', # yellow - '#4EC93B', # green - '#881F93', # purple - '#C5752B') # orange -fig_spec$discrete_colors_light <- - c('#FCB3B3', # red - '#A7DDFC', # blue - '#FAEC8E' # yellow - ) - -fig_spec$sex_colors <- - c(`m` = '#806152', `f` = '#1E8B8F') - -# Export function ------------------------------------------------- - -fig_spec$ExportPDF <- - function (figure, filename, path, ...) { - ggsave( - filename = paste0(filename, '.pdf'), - plot = figure, - path = path, - units = 'mm', - dpi = 300, - useDingbats = FALSE, - ... - ) - } - -fig_spec$ExportPNG <- - function (figure, filename, path, ...) { - ggsave( - filename = paste0(filename, '.png'), - plot = figure, - path = path, - units = 'mm', - dpi = 300, - ... - ) - } +# figure specs +fig_spec <- list() + +# ggplot theme ---------------------------------------------------- + +# ggplot theme by Jonas Schöley +fig_spec$MyGGplotTheme <- + function ( + size = 8, + family = 'sans', + scaler = 1, + axis = 'x', + panel_border = FALSE, + grid = 'y', + minor_grid = '', + show_legend = TRUE, + ar = NA + ) { + + size_med = size*scaler + size_sml = round(size*0.7)*scaler + base_linesize = 0.3*scaler + + list( + theme_minimal(base_size = size_med, base_family = family), + theme( + # basic + text = element_text(color = 'black'), + line = element_line(size = base_linesize, lineend = 'square'), + # axis + #axis.line.y = element_blank(), + axis.title = element_text(size = size_med, face = 'bold'), + #axis.ticks = element_line(size = rel(0.5), color = 'black'), + axis.text = element_text(size = size_med, color = 'black'), + # strips + strip.text = element_text(color = 'black', size = size_med), + strip.background = element_blank(), + # plot + title = element_text(face = 'bold'), + plot.subtitle = element_text(color = 'black', size = size_med, face = 'bold'), + plot.caption = element_text(color = 'black', size = size_sml, face = 'plain'), + plot.background = element_blank(), + panel.background = element_blank(), + #plot.margin = unit(c(1, 0.1, 0.5, 0.5), units = 'mm'), + # grid + panel.grid = element_blank() + ), + if (identical(grid, 'y')) { + theme(panel.grid.major.y = + element_line(size = base_linesize, linetype = 3, color = 'grey80')) + }, + if (identical(grid, 'x')) { + theme(panel.grid.major.x = + element_line(size = base_linesize, linetype = 3, color = 'grey80')) + }, + if (identical(grid, 'xy') | identical(grid, 'yx')) { + theme(panel.grid.major.y = + element_line(size = base_linesize, linetype = 3, color = 'grey80'), + panel.grid.major.x = + element_line(size = base_linesize, linetype = 3, color = 'grey80')) + }, + if (identical(minor_grid, 'y')) { + theme(panel.grid.minor.y = + element_line(size = base_linesize, linetype = 3, color = 'grey80')) + }, + if (identical(minor_grid, 'x')) { + theme(panel.grid.minor.x = + element_line(size = base_linesize, linetype = 3, color = 'grey80')) + }, + if (identical(minor_grid, 'xy') | identical(grid, 'yx')) { + theme(panel.grid.minor.y = + element_line(size = base_linesize, linetype = 3, color = 'grey80'), + panel.grid.minor.x = + element_line(size = base_linesize, linetype = 3, color = 'grey80')) + }, + if (isTRUE(panel_border)) { + theme( + panel.border = + element_rect(fill = NA) + ) + }, + if (!isTRUE(show_legend)) { + theme(legend.position = 'none') + }, + if (axis == 'x') { + theme( + axis.line.x = element_line(linetype = 1, color = 'black') + ) + }, + if (axis == 'y') { + theme( + axis.line.y = element_line(linetype = 1, color = 'black') + ) + }, + if (axis == 'xy') { + theme( + axis.line = element_line(linetype = 1, color = 'black') + ) + }, + if (!is.na(ar)) { + theme( + aspect.ratio = ar + ) + } + ) + } + + +# Dimensions ------------------------------------------------------ + +# figure width (mm) +fig_spec$width = 170 + +# Colors ---------------------------------------------------------- + +# color palette +fig_spec$discrete_colors <- + c('#D23737', # red + '#3191C9', # blue + '#D2BC2D', # yellow + '#4EC93B', # green + '#881F93', # purple + '#C5752B') # orange +fig_spec$discrete_colors_light <- + c('#FCB3B3', # red + '#A7DDFC', # blue + '#FAEC8E' # yellow + ) + +fig_spec$sex_colors <- + c(`m` = '#806152', `f` = '#1E8B8F') + +# Export function ------------------------------------------------- + +fig_spec$ExportPDF <- + function (figure, filename, path, ...) { + ggsave( + filename = paste0(filename, '.pdf'), + plot = figure, + path = path, + units = 'mm', + dpi = 300, + useDingbats = FALSE, + ... + ) + } + +fig_spec$ExportPNG <- + function (figure, filename, path, ...) { + ggsave( + filename = paste0(filename, '.png'), + plot = figure, + path = path, + units = 'mm', + dpi = 300, + ... + ) + }