From 5e4962f52336d07fe96e2b0e05690140bfffaff8 Mon Sep 17 00:00:00 2001 From: Marianna Rottoli <marianna.rottoli@mail.polimi.it> Date: Fri, 29 May 2020 11:20:55 +0200 Subject: [PATCH] Dashboard: emissions changed, plots rearranged, layout improvements. --- scripts/output/comparison/EDGEcomparison.R | 140 ++++++++---------- .../notebook_templates/EDGEdashboard.Rmd | 134 +++++++++++------ .../notebook_templates/helper_dashboard.R | 98 ++++++------ 3 files changed, 197 insertions(+), 175 deletions(-) diff --git a/scripts/output/comparison/EDGEcomparison.R b/scripts/output/comparison/EDGEcomparison.R index e653c0f..8e1fe3c 100644 --- a/scripts/output/comparison/EDGEcomparison.R +++ b/scripts/output/comparison/EDGEcomparison.R @@ -45,7 +45,7 @@ CO2km_int_newsales_all = NULL emidem_all = NULL EJfuelsPass_all = NULL EJfuelsFrgt_all = NULL -emipFosEl_all = NULL +emipSource_all = NULL scenNames <- getScenNames(outputdirs) EDGEdata_path <- path(outputdirs, paste("EDGE-T/")) @@ -331,88 +331,74 @@ emidemFun = function(emidem){ } -emipfosElFun = function(miffile, gdx){ +emipSourceFun = function(miffile){ + minyr <- 2015 maxyr <- 2100 - TWa_2_EJ <- 31.536 - GtC_2_MtCO2 <- 44 / 12 * 1000 - - prodSe <- readgdx(gdx, "vm_prodSe")[ - tall >= minyr & tall <= maxyr][, value := value*TWa_2_EJ] - setnames(prodSe, c("year", "region", "pe", "se", "te", "value")) - - - prodSyn <- prodSe[te == "MeOH"] - - prodSyn[, se := "synliq"] - prodSyn[, c("pe", "te") := NULL] - setnames(prodSyn, "value", "syn_val") - prodSyn <- rbind(prodSyn, CJ(year=c(2015, 2020), - region=prodSyn$region, - se="synliq", syn_val=0, - unique=T)) - - - ## Electricity consumption for H2 production - prodEl <- prodSe[se == "seel"] - prodEl[, allEl := sum(value), by=.(year, region)][ - , c("pe", "se", "te", "value", "tenames") := NULL - ] - prodEl <- unique(prodEl) - - prodElH2 <- prodSe[pe == "seel" & se == "seh2"] - prodElH2[, elh2 := sum(value), by=.(year, region)] - prodElH2[, c("pe", "se", "te", "value") := NULL] - prodElH2 <- unique(prodElH2) - - prodShare <- merge(prodEl, prodElH2, all=T) - prodShare[, netProd := allEl - elh2] - ## CO2 emission for electricity - vemi <- readgdx(gdx, "vm_emiTeDetail")[ttot >= minyr & ttot <= maxyr] - setnames(vemi, c("year", "region", "pe", "se", "te", "emi", "val")) - emico2 <- vemi[se == "seel" & emi == "co2"][ - , co2val := sum(val) * GtC_2_MtCO2, by=.(year, region)][ - , c("pe", "se", "te", "emi", "val") := NULL - ] - emico2 <- unique(emico2) - - emico2 <- merge(emico2, prodShare, by=c("year", "region")) - emico2[, int := co2val/allEl] # MtCO2/EJ -> tCO2/MJ - - ## emissions from electricity for hydrogen production - emisyn <- emico2[, .(se="seh2", co2 = int * elh2), by=.(year, region)] # MtCO2 - - ## add electric cars upstream emissions - bevemi = miffile[ - variable == "Emi|CO2|Transport|Pass|Short-Medium Distance|Electricity" & + ## fe hydrogen used for liquids consumption in passenger transport + h2liqp = miffile[ + variable == "FE|Transport|Pass|Liquids|Hydrogen" & year >= minyr & year <= maxyr][ - , .(year, region, se="bevs", co2=value)] - + , .(year, region, fes="feh2l", fe=value)] - ## fossil emissions - fosemi = miffile[ - variable == "Emi|CO2|Transport|Pass|Short-Medium Distance|Liquids" & + ## fe hydrogen used in passenger transport + h2p = miffile[ + variable == "FE|Transport|Pass|Hydrogen" & year >= minyr & year <= maxyr][ - , .(year, region, se="fos", co2=value)] - - - ## combine all - emi_all <- rbindlist(list( - emisyn, - bevemi, - fosemi)) + , .(year, region, fes="feh2", fe=value)] - ## sum bev and hydrogen upstream emissions - emi_wide <- dcast(emi_all, year+region ~ se)[, all_el := bevs + seh2] + ## elec used in passenger transport + elp = miffile[ + variable == "FE|Transport|Pass|Electricity" & + year >= minyr & year <= maxyr][ + , .(year, region, fes="el", fe=value)] - emi_result <- melt(emi_wide, - value.name="co2", - id.vars = c("year", "region"), - variable.name = "tech")[tech %in% c("all_el", "fos")] + ## final energy electricity + el = miffile[ + variable == "FE|+|Electricity" & + year >= minyr & year <= maxyr][ + , .(year, region, fes="el", fe=value)] + ## emission supply side from electricity + emiel = miffile[ + variable == "Emi|CO2|Energy|Supply|Electricity|Gross" & + year >= minyr & year <= maxyr][ + , .(year, region, emis="el", emi=value)] - return(emi_result) + ## emissions from transport passenger + emip = miffile[ + variable == "Emi|CO2|Transport|Pass|Short-Medium Distance|Liquids" & + year >= minyr & year <= maxyr][ + , .(year, region, source="liq", emi=value)] + + ## calculate fossil electricity carbon intensity + elint = merge(el, emiel, by = c("year", "region")) + elint[, int := emi/fe] + elint = elint[,.(year, region, int)] + + ## calculate emissions from electricity of electrified transport + emielp = merge(elint, elp, by = c("year", "region")) + emielp[, emi := int*fe] + emielp = emielp[,.(year, region, emi, source = "elp")] + ## estimate the secondary energy from electricity based synfuels in passenger transport + sesynp = h2liqp[][, se := fe/0.55][, fe := NULL] + + ## estimate the secondary energy from hydrogen in passenger transport + seh2np = h2p[][, se := fe/0.7][, fe := NULL] + + ## emissions CO2 derived from synfuels in passenger transport + emisynp = merge(sesynp, elint, by = c("year", "region")) + emisynp[, emi := se*int] + emisynp = emisynp[,.(year, region, emi, source = "synf")] + ## emissions CO2 derived from hydrogen + emih2p = merge(seh2np, elint, by = c("year", "region")) + emih2p[, emi := se*int] + emih2p = emih2p[,.(year, region, emi, source = "h2")] + ## summarize emissions + emi_all = rbindlist(list(emih2p, emisynp, emielp, emip), use.names=TRUE) + + return(emi_all) } for (outputdir in outputdirs) { @@ -471,7 +457,7 @@ for (outputdir in outputdirs) { ## calculate demand emissions emidem = emidemFun(emidem) ## calculate emissions from passenger SM fossil fuels (liquids) - emipFosEl = emipfosElFun(miffile, gdx) + emipSource = emipSourceFun(miffile) ## add scenario dimension to the results fleet[, scenario := as.character(unique(miffile$scenario))] salescomp[, scenario := unique(miffile$scenario)] @@ -483,7 +469,7 @@ for (outputdir in outputdirs) { emidem[, scenario := as.character(unique(miffile$scenario))] EJfuelsPass[, scenario := as.character(unique(miffile$scenario))] EJfuelsFrgt[, scenario := as.character(unique(miffile$scenario))] - emipFosEl[, scenario := as.character(unique(miffile$scenario))] + emipSource[, scenario := as.character(unique(miffile$scenario))] ## rbind scenarios salescomp_all = rbind(salescomp_all, salescomp) fleet_all = rbind(fleet_all, fleet) @@ -495,7 +481,7 @@ for (outputdir in outputdirs) { emidem_all = rbind(emidem_all, emidem) EJfuelsPass_all = rbind(EJfuelsPass_all, EJfuelsPass) EJfuelsFrgt_all = rbind(EJfuelsFrgt_all, EJfuelsFrgt) - emipFosEl_all = rbind(emipFosEl_all, emipFosEl) + emipSource_all = rbind(emipSource_all, emipSource) } outdir = paste0("output/comparerunEDGE", gsub(" | ^([[:alpha:]]*).*","", Sys.time())) @@ -513,7 +499,7 @@ saveRDS(CO2km_int_newsales_all, paste0(outdir, "/CO2km_int_newsales_all.RDS")) saveRDS(emidem_all, paste0(outdir, "/emidem_all.RDS")) saveRDS(EJfuelsPass_all, paste0(outdir, "/EJfuelsPass_all.RDS")) saveRDS(EJfuelsFrgt_all, paste0(outdir, "/EJfuelsFrgt_all.RDS")) -saveRDS(emipFosEl_all, paste0(outdir, "/emipFosEl_all.RDS")) +saveRDS(emipSource_all, paste0(outdir, "/emipSource_all.RDS")) file.copy(file.path("./scripts/output/comparison/notebook_templates", md_template), outdir) rmarkdown::render(path(outdir, md_template), output_format="pdf_document") diff --git a/scripts/output/comparison/notebook_templates/EDGEdashboard.Rmd b/scripts/output/comparison/notebook_templates/EDGEdashboard.Rmd index 90d8e2b..dff83d1 100644 --- a/scripts/output/comparison/notebook_templates/EDGEdashboard.Rmd +++ b/scripts/output/comparison/notebook_templates/EDGEdashboard.Rmd @@ -38,8 +38,34 @@ legend=plotlist$legend #data frame with help tooltips helpTooltip_df <- data.frame( - title=c("Distance traveled per capita", "Total Passenger Transport Energy Services Demand", "Sales composition", "Final energy LDVs by fuel","Transport Passenger Final Energy Demand", "Fleet composition", "Fleet composition comparison", "Emission intensity, new sales comparison", "Comparison of passenger final energy demand", "Emissions passenger transport", "Emission intensity of new sales", "Comparison of sales composition", "Comparison of passenger transport fossil fuels emissions", "Comparison of passenger electricity production emissions"), - placement=c("right", "left", "right", "left", "right", "right", "right", "right", "right", "left", "left", "right", "left", "left")) + title=c("Distance traveled per capita", + "Total Passenger Transport Energy Services Demand", + "Sales composition", + "Final energy LDVs by fuel", + "Transport Passenger Final Energy Demand", + "Fleet composition", + "Fleet composition comparison", + "Emission intensity, new sales comparison", + "Comparison of passenger final energy demand", + "Passenger transport emissions supply and demand", + "Emission intensity of new sales", + "Comparison of sales composition", + "Comparison of passenger transport emissions supply and demand", + "Comparison of passenger tailpipe emissions from fossil fuels"), + placement=c("right", + "left", + "right", + "left", + "right", + "right", + "right", + "left", + "right", + "left", + "left", + "right", + "right", + "left")) helpTooltip = function(tooltipdf){ @@ -112,7 +138,7 @@ Row {data-height=300} ### Transport scenario {data-width=100} ```{r} -valueBox("Conventional Case NoTax") +valueBox("Baseline") ``` @@ -439,33 +465,37 @@ Row {data-height = 450} plotlist$comparison$plot$vintscen ``` -### Comparison of passenger final energy demand +### Comparison of sales composition ```{r} -plotlist$comparison$plot$EJpassfuels_scen +plotlist$comparison$plot$salescom_scen ``` -### Comparison of passenger transport fossil fuels emissions - +### Emission intensity, new sales comparison ```{r} -plotlist$comparison$plot$emipfos_scen +plotlist$comparison$plot$CO2km_intensity_newsales_scen ``` Row {data-height = 450} ----------------------------------------------------------------------- -### Comparison of sales composition +### Comparison of passenger final energy demand + ```{r} -plotlist$comparison$plot$salescom_scen +plotlist$comparison$plot$EJpassfuels_scen ``` -### Emission intensity, new sales comparison + +### Comparison of passenger transport emissions supply and demand + ```{r} -plotlist$comparison$plot$CO2km_intensity_newsales_scen +plotlist$comparison$plot$emiptot_scen ``` -### Comparison of passenger electricity production emissions + +### Comparison of passenger tailpipe emissions from fossil fuels + ```{r} -plotlist$comparison$plot$emipel_scen +plotlist$comparison$plot$emipfos_scen ``` Passenger transport overview {data-icon="glyphicon glyphicon-scale"} @@ -484,7 +514,7 @@ Row {data-height=300} ### Transport scenario {data-width=100} ```{r} -valueBox("Conventional Case NoTax") +valueBox("Baseline") ``` @@ -523,7 +553,7 @@ Row {data-heigth=500} plotlist$`ConvCase NoTax`$plot$EJpassfuels ``` -### Emissions passenger transport +### Passenger transport emissions supply and demand ```{r} plotlist$`ConvCase NoTax`$plot$emip @@ -586,7 +616,7 @@ Row {data-heigth=500} plotlist$ConvCase$plot$EJpassfuels ``` -### Emissions passenger transport +### Passenger transport emissions supply and demand ```{r} plotlist$ConvCase$plot$emip @@ -651,7 +681,7 @@ Row {data-heigth=500} plotlist$HydrHype$plot$EJpassfuels ``` -### Emissions passenger transport +### Passenger transport emissions supply and demand ```{r} plotlist$HydrHype$plot$emip @@ -714,7 +744,7 @@ Row {data-heigth=500} plotlist$ElecEra$plot$EJpassfuels ``` -### Emissions passenger transport +### Passenger transport emissions supply and demand ```{r} plotlist$ElecEra$plot$emip @@ -776,7 +806,7 @@ Row {data-heigth=500} plotlist$SynSurge$plot$EJpassfuels ``` -### Emissions passenger transport +### Passenger transport emissions supply and demand ```{r} plotlist$SynSurge$plot$emip @@ -790,49 +820,53 @@ Column {data-width= 450} ----------------------------------------------------------------------- ### Baseline (No Carbon Pricing) {data-height=200} -</ul> - <li> Structurally conservative: continuation of historic consumer preferences for conventional combustion engine cars. </li> - <li> No policies to promote alternative vehicles </li> - <li> Slow build-up of electric recharging stations </li> +</ul style="padding-left:20px"> + <li class="shift"> Structurally conservative: continuation of historic consumer preferences for conventional combustion engine cars. </li> + <li class="shift"> No policies to promote alternative vehicles </li> + <li class="shift"> Slow build-up of electric recharging stations </li> </ul> ### Conventional Case {data-height=200} -</ul> - <li> Structurally conservative: continuation of historic consumer preferences for conventional combustion engine cars </li> - <li> No policies to promote alternative vehicles </li> - <li> Slow build-up of electric recharging stations </li> +</ul style="padding-left:20px"> + <li class="shift"> Carbon pricing </li> + <li class="shift"> Structurally conservative: continuation of historic consumer preferences for conventional combustion engine cars </li> + <li class="shift"> No policies to promote alternative vehicles </li> + <li class="shift"> Slow build-up of electric recharging stations </li> </ul> ### Hydrogen Hype {data-height=200} -</ul> - <li> Fast build-up of hydrogen refuelling stations </li> - <li> Rebates-feebates scheme: FCEVs receive 5000€ subsidies for purchases in 2020, around 3300€ in 2025 and 1700€ in 2030. 1000€ mark-up cost on internal combustion engines are applied in 2020, 700€ in 2025 and 300€ in 2030 </li> - <li> Increasing dis-preference for internal combustion engines due to tightening regulation </li> - <li> Policy push for FCEVs: Support policies induce a shift from dis-preference to preference of hydrogen vehicles, e.g. incentives to carmakers and car retailers to provide hidrogen vehicles </li> - <li> Hydrogen from renewable resources (green hydrogen) is at least 95% of the total hydrogen </li> - <li> Slow build-up of electric recharging stations </li> +</ul style="padding-left:20px"> + <li class="shift"> Carbon pricing </li> + <li class="shift"> Fast build-up of hydrogen refuelling stations </li> + <li class="shift"> Rebates-feebates scheme: FCEVs receive 5000€ subsidies for purchases in 2020, around 3300€ in 2025 and 1700€ in 2030. 1000€ mark-up cost on internal combustion engines are applied in 2020, 700€ in 2025 and 300€ in 2030 </li> + <li class="shift"> Increasing dis-preference for internal combustion engines due to tightening regulation </li> + <li class="shift"> Policy push for FCEVs: Support policies induce a shift from dis-preference to preference of hydrogen vehicles, e.g. incentives to carmakers and car retailers to provide hidrogen vehicles </li> + <li class="shift"> Hydrogen from electricity is at least 95% of the total hydrogen, with electricity from renewable resources reaching around 90% of the electricity production in 2050 </li> + <li class="shift"> Slow build-up of electric recharging stations </li> </ul> ### Electric Era {data-height=200} -</ul> - <li> Rebates-feebates scheme: BEVs receive 5000€ subsidies for purchases in 2020, around 3300€ in 2025 and 1700€ in 2030. 1000€ mark-up cost on internal combustion engines are applied in 2020, 700€ in 2025 and 300€ in 2030 </li> - <li> Increasing dis-preference for internal combustion engines due to tightening regulation </li> +</ul style="padding-left:20px"> + <li class="shift"> Carbon pricing </li> + <li class="shift"> Rebates-feebates scheme: BEVs receive 5000€ subsidies for purchases in 2020, around 3300€ in 2025 and 1700€ in 2030. 1000€ mark-up cost on internal combustion engines are applied in 2020, 700€ in 2025 and 300€ in 2030 </li> + <li class="shift"> Increasing dis-preference for internal combustion engines due to tightening regulation </li> </ul> ### Synfuel Surge {data-height=200} -</ul> - <li> Structurally conservative: continuation of historic consumer preferences for conventional combustion engine cars </li> - <li> Synfuels are forced in the liquids mix blending mandates reaching 10% of liquids fuels in transportation by 2035 </li> - <li> Hydrogen from renewable resources (green hydrogen) is at least 95% of the total hydrogen </li> - <li> CO<sub>2</sub> emissions from other sources (e.g., industrial installations) are captured and reused to produce syntethic fuels (Carbon Capture and Utilization) </li> +</ul style="padding-left:20px"> + <li class="shift"> Carbon pricing </li> + <li class="shift"> Structurally conservative: continuation of historic consumer preferences for conventional combustion engine cars </li> + <li class="shift"> Synfuels are forced in the liquids mix blending mandates reaching 20% of liquids fuels in transportation by 2035 </li> + <li class="shift"> Hydrogen from electricity is at least 95% of the total hydrogen, with electricity from renewable resources reaching around 90% of the electricity production in 2050</li> + <li class="shift"> CO<sub>2</sub> emissions from other sources (e.g., industrial installations) are captured and reused to produce syntethic fuels (Carbon Capture and Utilization) </li> </ul> @@ -1001,7 +1035,7 @@ navBarMemory = function(topMenuLabel, sideBarClass){ user-select: none; } -<!-- element "legend" of panels --> +/*legend element with tooltip*/ .rightal { float: right; font-weight: bold; @@ -1009,11 +1043,13 @@ navBarMemory = function(topMenuLabel, sideBarClass){ color: #7c7c7c; padding: 5px 10px; } + +ul{ + list-tyle:none; +} -<!-- indentation for bullet points list --> - li{ +.shift{ margin-left:20px; - } - - +} + </style> diff --git a/scripts/output/comparison/notebook_templates/helper_dashboard.R b/scripts/output/comparison/notebook_templates/helper_dashboard.R index fb48dd8..d789ba9 100644 --- a/scripts/output/comparison/notebook_templates/helper_dashboard.R +++ b/scripts/output/comparison/notebook_templates/helper_dashboard.R @@ -67,12 +67,10 @@ cols <- c("NG" = "#d11141", "Hydrogen_push" = "#00aedb", "Conservative_liquids" = "#113245", "ConvCase" = "#113245", - "ConvCaseNoTax" = "#d11141", + "Baseline" = "#d11141", "ConvCaseWise" = "#d11141", "SynSurge" = "orchid", - "Fossil fuels" = "#113245", - "Fossil fuels + Electricity production" = "#f37735", - "Electricity production" = "#6495ed") + "Fossil fuels" = "#113245") legend_ord_modes <- c("Freight Rail", "Truck", "Shipping", "International Shipping", "Domestic Shipping", "Trucks", "Motorbikes", "Small Cars", "Large Cars", "Van", @@ -96,7 +94,7 @@ ESmodecap_all = readRDS("ESmodecap_all.RDS") ESmodeabs_all = readRDS("ESmodeabs_all.RDS") CO2km_int_newsales_all = readRDS("CO2km_int_newsales_all.RDS") EJpass_all = readRDS("EJfuelsPass_all.RDS") -emipFosEl_all = readRDS("emipFosEl_all.RDS") +emipSource_all = readRDS("emipSource_all.RDS") ## scenarios scens = unique(EJmode_all$scenario) @@ -142,13 +140,13 @@ vintcomparisondash = function(dt, scen){ vintscen_dash = function(dt){ - dt[, scenario := ifelse(scenario == "Base_ConvCase", "ConvCaseNoTax", scenario)] + dt[, scenario := ifelse(scenario == "Base_ConvCase", "Baseline", scenario)] dt = dt[year %in% c(2020, 2030, 2050)] dt[, year := as.character(year)] dt = dt[region == region_plot] dt = dt[,.(value = sum(value)), by = c("region", "technology", "year", "scenario")] dt[, scenario := gsub(".*_", "", scenario)] - dt[, scenario := factor(scenario, levels = c("ConvCaseNoTax", "ConvCase", "HydrHype", "ElecEra", "SynSurge"))] + dt[, scenario := factor(scenario, levels = c("Baseline", "ConvCase", "HydrHype", "ElecEra", "SynSurge"))] dt[, details := paste0("Vehicles: ", round(value, 0), " [million]", "<br>", "Technology: ", technology, "<br>", "Region: ", region," <br>", "Year: ", year) ] g1 = ggplot()+ geom_bar(data = dt[year %in% c(2030, 2050)], @@ -247,7 +245,7 @@ salescomdash = function(dt, scen){ ESmodecapdash = function(dt, scen){ dt = dt[region == region_plot & scenario == scen & year <= 2050] - dt[, details := paste0("Demand: ", round(cap_dem, digits = 0), ifelse(mode == "pass", " [pkm/cap]", " [tkm/cap]"), "<br>", "Vehicle: ", vehicle_type_plot, "<br>", "Region: ", region," <br>", "Year: ", year) ] + dt[, details := paste0("Demand: ", round(cap_dem, digits = 0), ifelse(mode == "pass", " [km]", " [tkm/cap]"), "<br>", "Vehicle: ", vehicle_type_plot, "<br>", "Region: ", region," <br>", "Year: ", year) ] plot_pass = ggplot()+ geom_area(data = dt[mode == "pass"], aes(x = year, y = cap_dem, group = vehicle_type_plot, fill = vehicle_type_plot, text = details), position= position_stack())+ @@ -371,12 +369,12 @@ EJpass_dash = function(dt, scen){ } EJpass_scen_dash = function(dt){ - dt[, scenario := ifelse(scenario == "Base_ConvCase", "ConvCaseNoTax", scenario)] + dt[, scenario := ifelse(scenario == "Base_ConvCase", "Baseline", scenario)] dt[, subtech := factor(subtech, levels = legend_ord)] dt = dt[region == region_plot & year %in% c(2020, 2030, 2050) & sector == "trn_pass"] dt[, details := paste0("Demand: ", round(demand_EJ, digits = 0), " [EJ]","<br>", "Technology: ", subtech, "<br>", "Region: ", region," <br>", "Year: ", year) ] dt[, scenario := gsub(".*_", "", scenario)] - dt[, scenario := factor(scenario, levels = c("ConvCaseNoTax", "ConvCase", "HydrHype", "ElecEra", "SynSurge"))] + dt[, scenario := factor(scenario, levels = c("Baseline", "ConvCase", "HydrHype", "ElecEra", "SynSurge"))] g1 = ggplot()+ geom_bar(data = dt[year %in% c(2030, 2050)], aes(x = scenario, y = demand_EJ, group = subtech, @@ -470,7 +468,7 @@ CO2km_intensity_newsalesdash = function(dt, scen){ CO2km_intensity_newsales_scen_dash = function(dt){ - dt[, scenario := ifelse(scenario == "Base_ConvCase", "ConvCaseNoTax", scenario)] + dt[, scenario := ifelse(scenario == "Base_ConvCase", "Baseline", scenario)] 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)) historical_values[, details := "Historical values"] targets = data.table(name = c("2021 target", "2025 target", "2030 target"), value = c(95, 95*(1-0.15), 95*(1-0.37))) @@ -553,20 +551,20 @@ EJLDVdash <- function(dt, scen){ emip_dash = function(dt, scen){ dt[, year:= as.numeric(year)] dt = dt[region == region_plot & scenario == scen & year <= 2050 & year >= 2020] - dt = dcast(dt, region + year + scenario ~ tech, value.var = "co2") + dt = dcast(dt, region + year + scenario ~ source, value.var = "emi") - dt[, tot := fos + all_el] dt = melt(dt, id.vars = c("region", "year", "scenario")) - dt[variable == "tot", type := "Fossil fuels + Electricity production"] - dt[variable == "all_el", type := "Electricity production"] - dt[variable == "fos", type := "Fossil fuels"] + dt[variable == "synf", type := "Synfuel"] + dt[variable == "h2", type := "Hydrogen"] + dt[variable == "elp", type := "Electricity"] + dt[variable == "liq", type := "Fossil fuels"] + dt[variable == "synf" & value <0, value := 0] dt[, details := paste0("Emissions: ", round(value, digits = 0), " [MtCO<sub>2</sub>]", "<br>", "Type: ", type, "<br>", "Region: ", region," <br>", "Year: ", year) ] plot = ggplot()+ - geom_area(data = dt[year >= 2020 & type == "Fossil fuels + Electricity production"], aes(x = year, y = value, text = details, fill =type, group = type), alpha = 0.4, position = position_stack())+ - geom_line(data = dt[year >= 2020 & type != "Fossil fuels + Electricity production"], aes(x = year, y = value, text = details, group = type, color = type))+ + geom_bar(data = dt[year >= 2020], aes(x = year, y = value, text = details, fill = type, group = type), position = position_stack(), stat = "identity")+ labs(x = "", y = "")+ theme_minimal()+ expand_limits(y = c(0,1))+ @@ -597,24 +595,26 @@ emip_dash = function(dt, scen){ } emipscen_dash = function(dt){ - dt = dt[region == region_plot & year <= 2050 & year >= 2020] + dt = dt[region == region_plot & year <= 2050 & year >= 2015] dt[, year := as.numeric(year)] - dt[, scenario := ifelse(scenario == "Base_ConvCase", "ConvCaseNoTax", scenario)] + dt[, scenario := ifelse(scenario == "Base_ConvCase", "Baseline", scenario)] dt[, scenario := gsub(".*_", "", scenario)] + dt = dt[scenario != "Baseline"] + dt = dcast(dt, region + year + scenario ~ source, value.var = "emi") - dt = dcast(dt, region + year + scenario ~ tech, value.var = "co2") - - dt[, tot := fos + all_el] + dt[, tot := h2 + synf + elp + liq] dt = melt(dt, id.vars = c("region", "year", "scenario")) - dt[variable == "tot", type := "Fossil fuels + Electricity production"] - dt[variable == "all_el", type := "Electricity production"] - dt[variable == "fos", type := "Fossil fuels"] - + dt[variable == "tot", type := "Passenger transport emissions, supply and demand"] + dt[variable == "synf", type := "Synfuels"] + dt[variable == "h2", type := "Hydrogen"] + dt[variable == "elp", type := "Electricity"] + dt[variable == "liq", type := "Fossil fuels"] + dt[, details := scenario ] - pfos = ggplot()+ - geom_line(data = dt[type == "Fossil fuels"], aes(x = year, y = value, text = details, group = scenario, color = scenario))+ + ptot = ggplot()+ + geom_line(data = dt[variable == "tot"], aes(x = year, y = value, text = details, group = scenario, color = scenario))+ labs(x = "", y = "")+ theme_minimal()+ expand_limits(y = c(0,1))+ @@ -630,19 +630,19 @@ emipscen_dash = function(dt){ strip.background = element_rect(color = "grey"))+ scale_color_manual(values = cols) - pfos = ggplotly(pfos, tooltip = c("text")) %>% + ptot = ggplotly(ptot, tooltip = c("text")) %>% config(modeBarButtonsToRemove=plotlyButtonsToHide, displaylogo=FALSE) %>% layout(yaxis=list(title='[MtCO<sub>2</sub>]', titlefont = list(size = 10))) vars = as.character(unique(dt$scenario)) - pel = ggplot()+ - geom_line(data = dt[type == "Electricity production"], aes(x = year, y = value, text = scenario, group = scenario, color = scenario))+ + pfos = ggplot()+ + geom_line(data = dt[variable == "liq"], aes(x = year, y = value, text = scenario, group = scenario, color = scenario))+ labs(x = "", y = "")+ theme_minimal()+ expand_limits(y = c(0,1))+ - ylim(-80, 140)+ + ylim(0, 1800)+ scale_x_continuous(breaks = c(2020, 2030, 2050))+ theme(axis.text.x = element_text(angle = 90, size = 8, vjust=0.5, hjust=1), axis.text.y = element_text(size = 8), @@ -654,11 +654,11 @@ emipscen_dash = function(dt){ strip.background = element_rect(color = "grey"))+ scale_color_manual(values = cols) - pel = ggplotly(pel, tooltip = c("text")) %>% + pfos = ggplotly(pfos, tooltip = c("text")) %>% config(modeBarButtonsToRemove=plotlyButtonsToHide, displaylogo=FALSE) %>% layout(yaxis=list(title='[MtCO<sub>2</sub>]', titlefont = list(size = 10))) - plot = list(pfos = pfos, pel = pel, vars = vars) + plot = list(pfos = pfos, ptot = ptot, vars = vars) return(plot) @@ -667,11 +667,11 @@ emipscen_dash = function(dt){ salescom_scen_dash = function(dt){ dt[, scenario := as.character(scenario)] - dt[, scenario := ifelse(scenario == "Base_ConvCase", "ConvCaseNoTax", scenario)] + dt[, scenario := ifelse(scenario == "Base_ConvCase", "Baseline", scenario)] dt = dt[region == region_plot & year %in% c(2020, 2030, 2050)] dt[, year := as.numeric(as.character(year))] dt[, scenario := gsub(".*_", "", scenario)] - dt[, scenario := factor(scenario, levels = c("ConvCaseNoTax", "ConvCase", "HydrHype", "ElecEra", "SynSurge"))] + dt[, scenario := factor(scenario, levels = c("Baseline", "ConvCase", "HydrHype", "ElecEra", "SynSurge"))] ## normalize shares so to have sum to 1 dt[, shareFS1 := round(shareFS1*100, digits = 0)] dt[, shareFS1 := shareFS1/sum(shareFS1), by = c("region", "year", "scenario")] @@ -767,7 +767,7 @@ create_plotlist = function(scens, salescomp_all, fleet_all, ESmodecap_all, EJfue ## final energy LDVs by fuel EJLDV = EJLDVdash(EJroad_all, scen) ## emissions passenger transport demand and upstream emissions - emip = emip_dash(emipFosEl_all, scen) + emip = emip_dash(emipSource_all, scen) ## collect plots output[[scenname]]$plot$vintcomp = vintcomp$plot @@ -792,7 +792,7 @@ create_plotlist = function(scens, salescomp_all, fleet_all, ESmodecap_all, EJfue ## sales salescom_scen = salescom_scen_dash(salescomp_all) ## emissions - emip_scen = emipscen_dash(emipFosEl_all) + emip_scen = emipscen_dash(emipSource_all) output[["comparison"]]$plot$vintscen = vintscen$plot @@ -800,7 +800,7 @@ create_plotlist = function(scens, salescomp_all, fleet_all, ESmodecap_all, EJfue output[["comparison"]]$plot$EJpassfuels_scen = EJpassfuels_scen$plot output[["comparison"]]$plot$salescom_scen = salescom_scen$plot output[["comparison"]]$plot$emipfos_scen = emip_scen$pfos - output[["comparison"]]$plot$emipel_scen = emip_scen$pel + output[["comparison"]]$plot$emiptot_scen = emip_scen$ptot @@ -816,9 +816,9 @@ create_plotlist = function(scens, salescomp_all, fleet_all, ESmodecap_all, EJfue names(legend$'Total Passenger Transport Energy Services Demand'$contents) <- ESmodeabs$vars legend$'Total Passenger Transport Energy Services Demand'$description <- "<p>Energy services demand, passenger transport</p>" - legend$'Emissions passenger transport'$contents <- lapply(emip$vars, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) }) - names(legend$'Emissions passenger transport'$contents) <- emip$vars - legend$'Emissions passenger transport'$description <- "<p>Emissions from fossil fuels and electricity production and use, passenger transport (international aviation excluded)<p>" + legend$'Passenger transport emissions supply and demand'$contents <- lapply(emip$vars, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) }) + names(legend$'Passenger transport emissions supply and demand'$contents) <- emip$vars + legend$'Passenger transport emissions supply and demand'$description <- "<p>Passenger transport emissions supply and demand<p>" legend$'Emission intensity of new sales'$description <- "CO<sub>2</sub> intensity of light duty vehicles sales, historical and projected values" @@ -857,13 +857,13 @@ create_plotlist = function(scens, salescomp_all, fleet_all, ESmodecap_all, EJfue names(legend$'Comparison of sales composition'$contents) <- salescom_scen$vars legend$'Comparison of sales composition'$description <- "<p>Composition of sales of light duty vehicles in selected years</p>" - legend$'Comparison of passenger transport fossil fuels emissions'$contents <- lapply(emip_scen$vars, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) }) - names(legend$'Comparison of passenger transport fossil fuels emissions'$contents) <- emip_scen$vars - legend$'Comparison of passenger transport fossil fuels emissions'$description <- "<p>Emissions from fossil fuels production and use in passenger transport</p>" + legend$'Comparison of passenger transport emissions supply and demand'$contents <- lapply(emip_scen$vars, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) }) + names(legend$'Comparison of passenger transport emissions supply and demand'$contents) <- emip_scen$vars + legend$'Comparison of passenger transport emissions supply and demand'$description <- "<p>Emissions from supply and demand, passenger transport (includes electricity-related, hydrogen-related, synfuels-related emissions)</p>" - legend$'Comparison of passenger electricity production emissions'$contents <- lapply(emip_scen$vars, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) }) - names(legend$'Comparison of passenger electricity production emissions'$contents) <- emip_scen$vars - legend$'Comparison of passenger electricity production emissions'$description <- "<p>Emissions from electricity production and consumption in passenger transport</p>" + legend$'Comparison of passenger tailpipe emissions from fossil fuels'$contents <- lapply(emip_scen$vars, function(var) { return(list("fill"=toString(cols[var]),"linetype"=NULL)) }) + names(legend$'Comparison of passenger tailpipe emissions from fossil fuels'$contents) <- emip_scen$vars + legend$'Comparison of passenger tailpipe emissions from fossil fuels'$description <- "<p>Tailpipe emissions of passenger transport, derived from fossil fuels consumption</p>" output$legend = legend return(output) -- GitLab