Skip to content
Snippets Groups Projects
Commit ea3c9514 authored by Marianna Rottoli's avatar Marianna Rottoli
Browse files

Regional plot with vintages saved with nice formatting.

parent 58709c19
No related branches found
No related tags found
1 merge request!194Updates to EDGE-Transport
......@@ -116,7 +116,8 @@ legend_ord_emissions <- c("Emi|CO2|Industry|Gross", "Emi|CO2|Buildings|Direct",
legend_ord = c(legend_ord_modes, legend_ord_fuels, legend_ord_costs)
## mapping for scenario names
mapping_scens = data.table(scenario = c("Budg1100_ConvCase", "Budg1100_ElecEra", "Budg1100_HydrHype", "Budg1100_SynSurge", "NDC_ConvCase", "Budg1100_ConvCaseWise", "Budg1100_ElecEraWise", "Budg1100_HydrHypeWise", "Budg1100_SynSurgeWise", "NDC_ConvCaseWise"), scen_name = c("ConvCase", "ElecEra", "HydrHype", "SynSurge", "Baseline", "ConvCaseWise", "ElecEraWise", "HydrHypeWise", "SynSurgeWise", "BaselineWise"))
regionplot = "EUR"
```
......@@ -460,14 +461,22 @@ emidem_pf(emidem_all)
## vintages
```{r, echo=FALSE, message=FALSE, warning=FALSE, fig.width=14, fig.height=12}
vintcomparison_regi_pf = function(dt, rp){
vintcomparison_regi_pf = function(dt, mapping_scens, rp){
dt = dt[year %in% c(2020, 2030, 2050) & region == rp]
## apply more esthetic scenario names
dt = merge(dt, mapping_scens, by = "scenario")
## if scenario name not available in the mapping, apply scenario extended name (e.g. NPi, Budget950... are not recorded in the mapping)
dt[is.na(scen_name), scen_name := scenario]
## define the maximum on the y-axis depending on the maximum value across scenarios
dt[, sum := sum(value), by = c("year", "scenario")]
dt[, maxval := max(sum)]
## select a random scenario for 2020 and attribute the label "Historical"
p1 = ggplot()+
geom_bar(data = dt[year == 2020 & scenario == unique(dt$scenario)[1]][, scenario := "Historical"],
aes(x=scenario, y=value, group= technology,
fill = technology, width=.75), position="stack", stat = "identity", width = 0.5)+
geom_bar(data = dt[year == 2020 & scenario == unique(dt$scenario)[1]][, scen_name := "Historical"],
aes(x=scen_name, y=value, group= technology,
fill = technology, width=.75), position="stack", stat = "identity", width = 0.5, alpha = 0.9)+
theme_minimal()+
ylim(0,500)+
ylim(0,unique(dt[, maxval]))+
facet_wrap(~ year, nrow = 1)+
theme(axis.text.x = element_text(angle = 90, size=14, vjust=0.5, hjust=1),
axis.text.y = element_text(size=14),
......@@ -483,20 +492,20 @@ vintcomparison_regi_pf = function(dt, rp){
p2 = ggplot()+
geom_bar(data = dt[year != 2020],
aes(x=scenario, y=value, group=interaction(variable, technology),
fill = technology, width=.75), position="stack", stat = "identity", width = 0.5)+
aes(x=scen_name, y=value, group=interaction(variable, technology),
fill = technology, width=.75), position="stack", stat = "identity", width = 0.5, alpha = 0.9)+
theme_minimal()+
ylim(0,500)+
ylim(0,unique(dt[, maxval]))+
facet_wrap(~ year, nrow = 1)+
theme(axis.text.x = element_text(angle = 90, size=14, vjust=0.5, hjust=1),
axis.text.y = element_text(size=14),
axis.text.y = element_blank(),
axis.title.y = element_text(size=14),
title = element_text(size=14),
axis.line = element_line(size = 0.5, colour = "grey"),
legend.text = element_text(size=14),
strip.text = element_text(size=14),
strip.background = element_rect(color = "grey"))+
guides(fill=guide_legend(title="Transport mode"))+
guides(fill=guide_legend(title="Powertrain"))+
scale_fill_manual(values = cols)+
labs(y = "", x="")
......@@ -505,7 +514,7 @@ vintcomparison_regi_pf = function(dt, rp){
return(plot)
}
p = vintcomparison_regi_pf(fleet_all, rp = regionplot)
p = vintcomparison_regi_pf(fleet_all, mapping_scens, rp = regionplot)
p
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment