Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
#quantile index column and column with quantile averages
#qidx: quantile index
#qavg_to_scale: column to scale
#first_target: target value of first quantile
#mean_target: target mean of scaled quantiles
scaled_quantiles <- function(.data,
qidx,
qavg_to_scale,
first_target,
mean_target) {
# cumbersomely extract current quantile mean
mean_current = .data %>%
ungroup() %>%
summarise(mean_cur = first(mean({{qavg_to_scale}}))) %>%
pull(mean_cur)
# cumbersomely extract current first wuantile value
first_current = .data %>%
ungroup() %>%
arrange({{qidx}}) %>%
summarise(first_cur = first({{qavg_to_scale}})) %>%
pull(first_cur)
df_tmp = .data %>%
mutate(tmp = {{qavg_to_scale}}*mean_target/mean_current)
first_tmp = df_tmp$tmp[1]
df_tmp = df_tmp %>%
mutate(scaled = mean_target-(mean_target-tmp) * (mean_target-first_target)/(mean_target-first_tmp)) %>%
select({{qidx}}, scaled) %>%
mutate(v_mean = mean_target, v_first = first_target)
}
## run once to save file
df_all = NULL
for (min_energy in seq(from=mer[1], to=mer[2], by=0.25)) {
for (mean_energy in seq(from=mea[1], to=mea[2], by=0.25)) {
if (min_energy <= mean_energy) {
df_all = df_all %>%
bind_rows(df_energy_deciles %>%
scaled_quantiles(eu_q_rank, pc_energy_use_gj, min_energy, mean_energy))
}
}
}
saveRDS(df_all, here("analysis/data/derived/si/scenarios_fine.rds"))
```
```{r , fig.width=7, fig.height=5.5, fig.cap="**Figure S6:**"}
round_by = 10
df_all = readRDS(here("analysis/data/derived/si/scenarios_fine.rds")) %>%
filter(eu_q_rank %in% c(1,10)) %>%
group_by(v_mean, v_first) %>%
summarise(ratio = last(scaled)/first(scaled)) %>%
mutate(bin_ratio = if_else((ratio*100)%%round_by > round_by*0.5,
ratio*100+(round_by-(ratio*100)%%round_by),
ratio*100-(ratio*100)%%round_by)) %>%
group_by(bin_ratio, v_first) %>%
summarise(v_mean = mean(v_mean)) %>%
mutate(bin_ratio = bin_ratio*0.01)
df_scenario = df_all %>%
filter(v_mean %in% df_scenario_info$fe_gj_pc) %>%
filter(!(scenario == "DLE")) %>%
mutate(scenario = dplyr::recode(scenario,
"LED" = "LED (33)",
"IEA ETP B2DS" = "IEA ETP B2DS (52)",
"GEA efficiency" = "GEA efficiency (40)",
"SSP1-1.9" = "SSP1-1.9 (54)",
"SSP2-1.9" = "SSP2-1.9 (58)",
"SSP4-1.9" = "SSP4-1.9 (64)",
"SSP3-3.4" = "SSP3-3.4 (90)",
"SSP5-6.0" = "SSP5-6.0 (94)"))
library(wesanderson)
a = df_all %>%
ggplot(aes(x=v_first, y=bin_ratio, fill=v_mean)) +
geom_hline(yintercept = ineq_curr, alpha=0.8, color="grey", linetype=2) +
geom_line(data=df_scenario, aes(color=scenario, group=scenario)) +
annotate(geom="text", x=max(df_all$v_first)-7.5,y=ineq_curr+0.6,label = "Current (2015) 10:10 ratio") +
#scale_fill_gradient("Mean energy\navailable (GJ/cap)",
# low=wes_palette("Chevalier1")[3],
# high = wes_palette("Rushmore1")[4]) +
#scale_color_manual(values=wes_palette("Darjeeling1")) +
theme_minimal() +
labs(x="Minimum energy requirement (GJ/cap)", y="Maximum energy inequality (10:10 ratio)", color = "Scenario")+
theme(text=element_text(family="Liberation Sans Narrow"),
axis.text.x = element_text(size = 13),
axis.text.y = element_text(size = 13)) +
#scale_color_discrete(name = "Scenario (mean GJ/cap)") +
xlim(10,53) +
#ylim(0,15) +
scale_y_continuous(breaks = c(2.5,5,7.5,10,12.5,15), limits = c(1,15)) +
scale_color_discrete(name = "Scenario\n(mean GJ/cap)", breaks=c("LED (33)",
"GEA efficiency (40)",
"IEA ETP B2DS (52)",
"SSP1-1.9 (54)",
"SSP2-1.9 (58)",
"SSP4-1.9 (64)",
"SSP3-3.4 (90)",
"SSP5-6.0 (94)")) #+
#theme_ipsum()
a
ggsave(here("analysis", "figures", "figureSxx.pdf"))
```
<!-- The following line ensures the references appear here for the MS Word or HTML output files, rather than right at the end of the document (this will not work for PDF files): -->
<div id="refs"></div>