diff --git a/out/appendix-6.png b/out/appendix-6.png index 1ffbe1c..35c3995 100644 Binary files a/out/appendix-6.png and b/out/appendix-6.png differ diff --git a/out/appendix-7.png b/out/appendix-7.png old mode 100755 new mode 100644 index fe99088..1ffbe1c Binary files a/out/appendix-7.png and b/out/appendix-7.png differ diff --git a/out/appendix-8.png b/out/appendix-8.png old mode 100644 new mode 100755 index 35c3995..fe99088 Binary files a/out/appendix-8.png and b/out/appendix-8.png differ diff --git a/src/7-prepare-data-for-viz.R b/src/7-prepare-data-for-viz.R index fb324fa..735a99d 100644 --- a/src/7-prepare-data-for-viz.R +++ b/src/7-prepare-data-for-viz.R @@ -124,7 +124,48 @@ save(qxdiff, file = "dat/qxdiff.rda" %>% lp) -# data for sens plateau 0.7 ----------------------------------------------- +# appendix six -- decomp changes in the sex gap ---------------- + +load("dat/gap_decomp.rda" %>% lp) +load("dat/years_max_gap.rda" %>% lp) + +# create labels with the period years +years_period <- years_max_gap %>% + pivot_wider(names_from = mark, values_from = year) %>% + transmute( + country, + early = paste0(first, "-\n", mid), + late = paste0(mid, "-\n", last) + ) %>% + pivot_longer(early:late, names_to = "period", values_to = "year_label") + +# transform the dataset for plotting +df_gap_decomp <- gap_decomp %>% + pivot_longer( + contains("ctb"), names_prefix = "ctb_", + names_to = "period", values_to = "ctb" + ) %>% + mutate( + age_group = age %>% + cut(c(0, 1, 15, 40, 60, 80, 111), right = FALSE) + ) %>% + group_by(country, period, age_group) %>% + summarise(ctb = ctb %>% sum(na.rm = T)) %>% + ungroup() %>% + mutate( + age_group = age_group %>% + str_replace(",", "-") %>% + as_factor() %>% + lvls_revalue(c("0", "1-14", "15-39", "40-59", "60-79", "80+")) + ) %>% + # attach labels + left_join(years_period) %>% + left_join(ids) + +save(df_gap_decomp, file = "dat/df_gap_decomp.rda" %>% lp) + + +# appendix seven -- data for sens plateau 0.7 --------------------- load("dat/decomp.rda" %>% lp) load("dat/decomp_de_07.rda" %>% lp) @@ -161,7 +202,7 @@ df_plateau <- decomp %>% save(df_plateau, file = "dat/df_plateau.rda" %>% lp) -# appendix seven -- sensitivity check for age boundary 50 vs 40 ------------ +# appendix eight -- sensitivity check for age boundary 50 vs 40 ------------ load("dat/gap33cntrs.rda" %>% lp) @@ -196,44 +237,3 @@ df50 <- df %>% ) save(df40, df50, file = "dat/df_40_50.rda" %>% lp) - - -# appendix eight -- decomp changes in the sex gap ---------------- - -load("dat/gap_decomp.rda" %>% lp) -load("dat/years_max_gap.rda" %>% lp) - -# create labels with the period years -years_period <- years_max_gap %>% - pivot_wider(names_from = mark, values_from = year) %>% - transmute( - country, - early = paste0(first, "-\n", mid), - late = paste0(mid, "-\n", last) - ) %>% - pivot_longer(early:late, names_to = "period", values_to = "year_label") - -# transform the dataset for plotting -df_gap_decomp <- gap_decomp %>% - pivot_longer( - contains("ctb"), names_prefix = "ctb_", - names_to = "period", values_to = "ctb" - ) %>% - mutate( - age_group = age %>% - cut(c(0, 1, 15, 40, 60, 80, 111), right = FALSE) - ) %>% - group_by(country, period, age_group) %>% - summarise(ctb = ctb %>% sum(na.rm = T)) %>% - ungroup() %>% - mutate( - age_group = age_group %>% - str_replace(",", "-") %>% - as_factor() %>% - lvls_revalue(c("0", "1-14", "15-39", "40-59", "60-79", "80+")) - ) %>% - # attach labels - left_join(years_period) %>% - left_join(ids) - -save(df_gap_decomp, file = "dat/df_gap_decomp.rda" %>% lp) diff --git a/src/8-figures.R b/src/8-figures.R index 6ca8e58..6f31854 100644 --- a/src/8-figures.R +++ b/src/8-figures.R @@ -883,7 +883,58 @@ ggsave( -# appendix six -- palteau 0.7 -------------------------------------------- +# appendix six -- change of gap decomposition --------------------------- + +load("dat/df_gap_decomp.rda" %>% lp) + +df_gap_decomp %>% + ggplot(aes(ctb, age_group))+ + geom_vline( + xintercept = 0, size = .5, color = "#999999" + )+ + geom_text( + data = . %>% filter(period == "early"), + aes(label = year_label %>% str_wrap(5), color = period), + family = font_rc, fontface = 2, + x = 1.5, y = 1.75, size = 4, lineheight = .9, alpha = .1 + )+ + geom_text( + data = . %>% filter(period == "late"), + aes(label = year_label %>% str_wrap(5), color = period), + family = font_rc, fontface = 2, + x = -1.5, y = 1.75, size = 4, lineheight = .9, alpha = .1 + )+ + geom_col( + aes(fill = period, color = period), + stat="identity", position="dodge", color = NA, width =.5 + )+ + facet_wrap(~name, ncol = 5, dir = "v")+ + scale_fill_manual(values = c("#003737FF", "#3FB3F7FF"))+ + scale_color_manual(values = c("#003737FF", "#3FB3F7FF"))+ + theme_minimal(base_family = font_rc, base_size = 14)+ + theme( + legend.position = "none", + panel.grid.minor = element_blank(), + panel.grid.major = element_line(size = .1), + panel.ontop = T + )+ + labs( + y = "Age group, years", + x = "Absolute contribution, years", + title = "Age-specific contributions to the change in the sex gap in life expectancy at birth" %>% str_wrap(60) + ) + +six_app <- last_plot() + +ggsave( + "out/appendix-6.png" %>% lp, + six, width = 8, height = 10, + type = "cairo-png" +) + + + +# appendix seven -- palteau 0.7 -------------------------------------------- load("dat/df_plateau.rda" %>% lp) # data is just for the Germany @@ -910,17 +961,17 @@ df_plateau %>% title = "Age-specific contribution to sex gap in life expectancy at birth", subtitle = "Comparison of the two assumptions of plateau level, Germany") -six_app <- last_plot() +seven_app <- last_plot() ggsave( - "out/appendix-6.png" %>% lp, - six_app, width = 6, height = 4.5, + "out/appendix-7.png" %>% lp, + seven_app, width = 6, height = 4.5, type = "cairo-png" ) -# appendix seven -- sensitivity check for age boundary 50 vs 40 ------------ +# appendix eight -- sensitivity check for age boundary 50 vs 40 ------------ load("dat/df_40_50.rda" %>% lp) df40 %>% ggplot()+ @@ -965,57 +1016,6 @@ df40 %>% ggplot()+ title = "Average contribution per year of age in the age group") -seven_app <- last_plot() - -ggsave( - "out/appendix-7.png" %>% lp, - seven_app, width = 8, height = 10, - type = "cairo-png" -) - - - -# appendix eight -- change of gap decomposition --------------------------- - -load("dat/df_gap_decomp.rda" %>% lp) - -df_gap_decomp %>% - ggplot(aes(ctb, age_group))+ - geom_vline( - xintercept = 0, size = .5, color = "#999999" - )+ - geom_text( - data = . %>% filter(period == "early"), - aes(label = year_label %>% str_wrap(5), color = period), - family = font_rc, fontface = 2, - x = 1.5, y = 1.75, size = 4, lineheight = .9, alpha = .1 - )+ - geom_text( - data = . %>% filter(period == "late"), - aes(label = year_label %>% str_wrap(5), color = period), - family = font_rc, fontface = 2, - x = -1.5, y = 1.75, size = 4, lineheight = .9, alpha = .1 - )+ - geom_col( - aes(fill = period, color = period), - stat="identity", position="dodge", color = NA, width =.5 - )+ - facet_wrap(~name, ncol = 5, dir = "v")+ - scale_fill_manual(values = c("#003737FF", "#3FB3F7FF"))+ - scale_color_manual(values = c("#003737FF", "#3FB3F7FF"))+ - theme_minimal(base_family = font_rc, base_size = 14)+ - theme( - legend.position = "none", - panel.grid.minor = element_blank(), - panel.grid.major = element_line(size = .1), - panel.ontop = T - )+ - labs( - y = "Age group, years", - x = "Absolute contribution, years", - title = "Age-specific contributions to the change in the sex gap in life expectancy at birth" %>% str_wrap(60) - ) - eight_app <- last_plot() ggsave(