Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
## script that prepares the plots
region_plot = "EUR"
require(ggplot2)
require(data.table)
require(plotly)
require(moinput)
require(magclass)
require(rmndt)
require(quitte)
require(devtools)
setConfig(forcecache=T)
## Aestethics Options
aestethics <- list("alpha"=0.6,
"line" = list("size"= 0.1),
"y-axis" = list("color"="#878787","size"= 1/3.78)
)
## Legends and colors
cols <- c("NG" = "#d11141",
"Liquids" = "#8c8c8c",
"Hybrid Liquids" = "#ffc425",
"Hybrid Electric" = "#f37735",
"BEV" = "#00b159",
"Electricity" = "#00b159",
"FCEV" = "#00aedb",
"Hydrogen" = "#00aedb",
"Biodiesel" = "#66a182",
"Synfuel" = "orchid",
"Oil" = "#2e4057",
"International Aviation" = "#9acd32",
"Domestic Aviation" = "#7cfc00",
"Bus" = "#32cd32",
"Passenger Rail" = "#2e8b57",
"Freight Rail" = "#ee4000",
"Trucks" = "#ff6a6a",
"International Shipping" = "#cd2626",
"Domestic Shipping" = "#ff4040",
"Shipping" = "#ff4040",
"Truck" = "#ff7f50",
"Motorbikes" = "#1874cd",
"Small Cars" = "#87cefa",
"Large Cars" = "#6495ed",
"Van" = " #40e0d0",
"LDV" = "#00bfff",
"Non motorized" = "#da70d6",
"Freight"="#ff0000",
"Freight (Inland)" = "#cd5555",
"Pass non LDV" = "#6b8e23",
"Pass" = "#66cdaa",
"Pass non LDV (Domestic)" = "#54ff9f",
"refined liquids enduse" = "#8c8c8c",
"FE|Transport|Hydrogen" = "#00aedb",
"FE|Transport|NG" = "#d11141",
"FE|Transport|Liquids" = "#8c8c8c",
"FE|Transport|Electricity" = "#00b159",
"FE|Transport" = "#1e90ff",
"FE|Buildings" = "#d2b48c",
"FE|Industry" = "#919191",
"ElecEra" = "#00b159",
"ElecEraWise" = "#68c6a4",
"HydrHype" = "#00aedb",
"HydrHypeWise" = "#o3878f",
"Hydrogen_push" = "#00aedb",
"Conservative_liquids" = "#113245",
"ConvCase" = "#113245",
"ConvCaseWise" = "#d11141")
legend_ord_modes <- c("Freight Rail", "Truck", "Shipping", "International Shipping", "Domestic Shipping", "Trucks",
"Motorbikes", "Small Cars", "Large Cars", "Van",
"International Aviation", "Domestic Aviation","Bus", "Passenger Rail",
"Freight", "LDV", "Pass non LDV", "Freight (Inland)", "Pass non LDV (Domestic)", "Non motorized")
legend_ord_fuels <- c("BEV", "Electricity", "Hybrid Electric", "FCEV", "Hydrogen", "Hybrid Liquids", "Liquids", "Oil", "Biodiesel", "Synfuel", "NG")
legend_ord = c(legend_ord_modes, legend_ord_fuels)
## Load files
EJmode_all = readRDS("EJmode_all.RDS")
EJLDV_all = readRDS("EJLDV_all.RDS")
fleet_all = readRDS("fleet_all.RDS")
salescomp_all = readRDS("salescomp_all.RDS")
ESmodecap_all = readRDS("ESmodecap_all.RDS")
CO2km_int_newsales_all = readRDS("CO2km_int_newsales_all.RDS")
EJfuels_all = readRDS("EJfuels_all.RDS")
emidem_all = readRDS("emidem_all.RDS")
## scenarios
scens = unique(EJmode_all$scenario)
## plot functions
vintcomparisondash = function(dt, scen){
dt = dt[year %in% c(2015, 2050, 2100)]
dt[, year := as.character(year)]
dt = dt[region == region_plot & scenario == scen]
plot = ggplot()+
geom_bar(data = dt,
aes(x=year, y=value, group=interaction(variable, technology),
fill = technology, width=.75), alpha = 0.5, position="stack", stat = "identity", width = 0.5)+
geom_bar(data = dt,
aes(x=year, y=value, group=interaction(variable, technology),
fill = technology, alpha = factor(alphaval), width=.75), position="stack", stat = "identity", width = 0.5, color = "black", size=0.05)+
guides(fill = guide_legend(reverse=TRUE))+
theme_minimal()+
theme(axis.text.x = element_text(angle = 90, size=8, vjust=0.5, hjust=1),
title = element_text(size=8),
axis.line = element_line(size = 0.5, colour = "grey"),
strip.text = element_text(size=8),
strip.background = element_rect(color = "grey"),
legend.position = "none")+
scale_alpha_discrete(breaks = c(1,0), name = "Status", labels = c("Vintages","New additions")) +
guides(linetype=FALSE,
fill=guide_legend(reverse=FALSE, title="Transport mode"))+
scale_fill_manual(values = cols)+
labs(x = "", y = "")
plot = ggplotly(plot)
vars = as.character(unique(dt$technology))
output = list(plot = plot,
vars = vars)
}
salescomdash = function(dt, scen){
dt = dt[region == region_plot & scenario == scen]
plot = ggplot()+
geom_bar(data = dt, aes(x=as.numeric(as.character(year)),y = shareFS1, group = technology, fill = technology), position = position_stack(), stat = "identity")+
theme_minimal()+
scale_fill_manual("Technology", values = cols)+
expand_limits(y = c(0,1))+
scale_x_continuous(breaks = c(2015, 2030, 2050, 2100))+
theme(axis.text.x = element_text(angle = 90, vjust=0.5, hjust=1, size = 8),
axis.text.y = element_text(size=8),
axis.line = element_line(size = 0.5, colour = "grey"),
axis.title = element_text(size = 8),
title = element_text(size = 8),
strip.text = element_text(size=8),
strip.background = element_rect(color = "grey"),
legend.position = "none")+
labs(x = "", y = "")
plot = ggplotly(plot)
## vars used for creating the legend in the dashboard
vars = as.character(unique(dt$technology))
output = list(plot = plot,
vars = vars)
return(output)
}
ESmodecapdash = function(dt, scen){
dt = dt[region == region_plot & scenario == scen]
plot_pass = ggplot()+
geom_area(data = dt[mode == "pass"], aes(x=year, y=cap_dem, group = vehicle_type_plot, fill = vehicle_type_plot), color="black", size=0.05, position= position_stack())+
labs(x = "", y = "")+
theme_minimal()+
scale_fill_manual("Vehicle Type", values = cols, breaks=legend_ord)+
expand_limits(y = c(0,1))+
scale_x_continuous(breaks = c(2015,2030,2050, 2100))+
theme(axis.text.x = element_text(angle = 90, size = 8, vjust=0.5, hjust=1),
axis.text.y = element_text(size = 8),
axis.title = element_text(size = 8),
title = element_text(size = 8),
legend.position = "none",
strip.text = element_text(size = 8),
strip.background = element_rect(color = "grey"),
axis.line = element_line(size = 0.5, colour = "grey"))
plot_frgt = ggplot()+
geom_area(data = dt[mode == "freight"], aes(x=year, y=cap_dem, group = vehicle_type_plot, fill = vehicle_type_plot), color="black", size=0.05, position= position_stack())+
labs(x = "", y = "")+
theme_minimal()+
scale_fill_manual("Vehicle Type", values = cols, breaks=legend_ord)+
expand_limits(y = c(0,1))+
scale_x_continuous(breaks = c(2015,2030,2050, 2100))+
theme(axis.text.x = element_text(angle = 90, size = 8, vjust=0.5, hjust=1),
axis.text.y = element_text(size = 8),
axis.title = element_text(size = 8),
title = element_text(size = 8),
legend.position = "none",
strip.text = element_text(size = 8),
strip.background = element_rect(color = "grey"),
axis.line = element_line(size = 0.5, colour = "grey"))
plot_pass = ggplotly(plot_pass)
plot_frgt = ggplotly(plot_frgt)
vars_pass = as.character(unique(dt[mode == "pass"]$vehicle_type_plot))
vars_frgt = as.character(unique(dt[mode == "freight"]$vehicle_type_plot))
output = list(plot = list(plot_pass = plot_pass, plot_frgt = plot_frgt),
vars = list(vars_pass = vars_pass, vars_frgt = vars_frgt))
return(output)
}
EJfuels_dash = function(dt, scen){
dt = dt[region == region_plot & scenario == scen & year >= 2015]
plot = ggplot()+
geom_area(data = dt, aes(x=year, y=demand_EJ, group = subtech, fill = subtech), color="black", size=0.05, position= position_stack())+
theme_minimal()+
scale_fill_manual("Technology",values = cols, breaks=legend_ord)+
expand_limits(y = c(0,1))+
labs(x = "", y = "")+
scale_x_continuous(breaks = c(2015,2030,2050, 2100))+
theme(axis.text.x = element_text(angle = 90, size = 8, vjust=0.5, hjust=1),
axis.text.y = element_text(size = 8),
axis.title = element_text(size = 8),
title = element_text(size = 8),
legend.position = "none",
strip.text = element_text(size = 8),
strip.background = element_rect(color = "grey"),
axis.line = element_line(size = 0.5, colour = "grey"))
plot = ggplotly(plot)
vars = as.character(unique(dt$subtech))
output = list(plot = plot,
vars = vars)
return(output)
}
CO2km_intensity_newsalesdash = function(dt, scen){
historical_values = data.table(year = c(2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018), emi = c(159, 157, 145, 140, 137, 132, 128, 124, 120, 119, 119, 120))
targets = data.table(name = c("2021 target", "2025 target", "2030 target"), value = c(95, 95*(1-0.15), 95*(1-0.37)))
dt = dt[!is.na(gCO2_km_ave) & region == region_plot & scenario == scen]
plot = ggplot()+
geom_line(data = dt[year >=2020], aes(x = year, y = gCO2_km_ave))+
geom_point(data = historical_values, aes(x = year, y= emi), color = "grey20")+
geom_hline(data = targets, aes(yintercept = value, linetype = name), color = "grey20", size=0.1)+
geom_text(data = targets, aes(y = value+5, x = c(2025, 2030, 2035), label = name), size = 3)+
expand_limits(y = c(0,1))+
labs(x = "", y = "")+
scale_x_continuous(breaks = c(2015, 2030, 2050, 2100))+
theme_minimal()+
theme(axis.text.x = element_text(angle = 90, size = 8, vjust=0.5, hjust=1),
axis.text.y = element_text(size = 8),
axis.title = element_text(size = 8),
title = element_text(size = 8),
legend.position = "none",
strip.text = element_text(size = 8),
strip.background = element_rect(color = "grey"),
axis.line = element_line(size = 0.5, colour = "grey"))+
guides(linetype = FALSE)
plot = ggplotly(plot)
return(plot)
}
EJLDVdash <- function(dt, scen){
dt[, technology := factor(technology, levels = legend_ord)]
dt = dt[region == region_plot & scenario == scen & year >= 2015]
plot = ggplot()+
geom_area(data = dt, aes(x=year, y=demand_EJ, group = technology, fill = technology), color="black", size=0.05, position= position_stack())+
labs(x = "", y = "")+
theme_minimal()+
scale_fill_manual("Technology", values = cols, breaks=legend_ord)+
expand_limits(y = c(0,1))+
scale_x_continuous(breaks = c(2015,2030,2050, 2100))+
theme(axis.text.x = element_text(angle = 90, size = 8, vjust=0.5, hjust=1),
axis.text.y = element_text(size = 8),
axis.title = element_text(size = 8),
axis.line = element_line(size = 0.5, colour = "grey"),
title = element_text(size = 8),
legend.position = "none",
strip.text = element_text(size=8),
strip.background = element_rect(color = "grey"))
plot = ggplotly(plot)
vars = as.character(unique(dt$technology))
output = list(plot = plot,
vars = vars)
return(output)
}
emidem_dash = function(dt, scen){
dt = dt[region == region_plot & scenario == scen]
plot = ggplot()+
geom_line(data = dt, aes(x = year, y = value))+
labs(x = "", y = "")+
theme_minimal()+
expand_limits(y = c(0,1))+
scale_x_continuous(breaks = c(2015, 2030, 2050, 2100))+
theme(axis.text.x = element_text(angle = 90, size = 8, vjust=0.5, hjust=1),
axis.text.y = element_text(size = 8),
axis.title = element_text(size = 8),
axis.line = element_line(size = 0.5, colour = "grey"),
title = element_text(size = 8),
legend.position = "none",
strip.text = element_text(size=8),
strip.background = element_rect(color = "grey"))
plot = ggplotly(plot)
return(plot)
}
legend = list()
create_plotlist = function(scens, salescomp_all, fleet_all, ESmodecap_all, EJfuels_all, CO2km_int_newsales_all, EJLDV_all){
output = NULL
for (scen in scens) {
## attribute scenario name
if (grepl("ConvCase", scen)) {
scenname = "ConvCase"
} else if (grepl("ElecEra", scen)) {
scenname = "ElecEra"
} else if (grepl("HydrHype", scen)) {
scenname = "HydrHype"
} else if (grepl("SynSurge", scen)) {
scenname = "SynSurge"
}
## CO2 tax pathway
emiscen = gsub("_.*", "", scen)
## sales
salescomp = salescomdash(salescomp_all, scen)
## vintages
vintcomp = vintcomparisondash(fleet_all, scen)
## energy services demand
ESmodecap = ESmodecapdash(ESmodecap_all, scen)
## final energy demand
EJfuels = EJfuels_dash(EJfuels_all, scen) ## Final Energy demand all modes, passenger and freight
## CO2 intensity new sales LDVs
CO2km_int_newsales = CO2km_intensity_newsalesdash(CO2km_int_newsales_all, scen)
## final energy LDVs by fuel
EJLDV = EJLDVdash(EJLDV_all, scen)
## emissions transport demand
emidem = emidem_dash(emidem_all, scen)
## collect plots
output[[scenname]]$plot$vintcomp = vintcomp$plot
output[[scenname]]$plot$salescomp = salescomp$plot
output[[scenname]]$plot$ESmodecap_pass = ESmodecap$plot$plot_pass
output[[scenname]]$plot$ESmodecap_frgt = ESmodecap$plot$plot_frgt
output[[scenname]]$plot$EJfuels = EJfuels$plot
output[[scenname]]$plot$CO2km_int_newsales = CO2km_int_newsales
output[[scenname]]$plot$EJLDV = EJLDV$plot
output[[scenname]]$plot$emidem = emidem
output[[scenname]]$emiscen = emiscen
}
legend$'Sales composition'$contents <- lapply(salescomp$vars, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) })
names(legend$'Sales composition'$contents) <- salescomp$vars
legend$'Per capita Passenger Transport Energy Services Demand'$contents <- lapply(ESmodecap$vars$vars_pass, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) })
names(legend$'Per capita Passenger Transport Energy Services Demand'$contents) <- ESmodecap$vars$vars_pass
legend$'Per capita Freight Transport Energy Services Demand'$contents <- lapply(ESmodecap$vars$vars_frgt, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) })
names(legend$'Per capita Freight Transport Energy Services Demand'$contents) <- ESmodecap$vars$vars_frgt
legend$'Final energy LDVs by fuel'$contents <- lapply(EJLDV$vars, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) })
names(legend$'Final energy LDVs by fuel'$contents) <- EJLDV$vars
legend$'Transport Final Energy Demand'$contents <- lapply(EJfuels$vars, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) })
names(legend$'Transport Final Energy Demand'$contents) <- EJfuels$vars
legend$'Fleet composition'$contents <- lapply(vintcomp$vars, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) })
names(legend$'Fleet composition'$contents) <- vintcomp$vars
output$legend = legend
return(output)
}
plotlist = create_plotlist(scens, salescomp_all, fleet_all, ESmodecap_all, EJfuels_all, CO2km_int_newsales_all, EJLDV_all)