Just Energy Transition Partnerships (all codes)

Author

Norah Zhang

Packages and Data Tidying

Show the code
library(formattable)
library(dplyr)
library(knitr)
library(tidyr)
library(readxl)

JETP <- read_xlsx("/Users/mac/SusFinExercise0202/FinalRawData.xlsx", sheet = 7)

share <- read_xlsx("/Users/mac/SusFinExercise0202/FinalRawData.xlsx", sheet = 2)
powermix <- read_xlsx("/Users/mac/SusFinExercise0202/FinalRawData.xlsx", sheet = 3)
powermix <- powermix %>%
  rename(Bioenergy = 'Electricity from bioenergy (TWh) (zero filled)',
         Coal = 'Electricity from coal (TWh)',
         Gas = 'Electricity from gas (TWh)',
         Hydro = 'Electricity from hydro (TWh)',
         Nuclear = 'Electricity from nuclear (TWh)',
         Oil = 'Electricity from oil (TWh)',
         Solar = 'Electricity from solar (TWh)',
         Wind = 'Electricity from wind (TWh)',
         Others = 'Other renewables excluding bioenergy (TWh) (zero filled)') %>%
  pivot_longer(cols = c("Others":"Coal"), names_to = "Source", values_to = "Electricity")

SA <- read_xlsx("/Users/mac/SusFinExercise0202/FinalRawData.xlsx", sheet = 4)

financialflow <- read_xlsx("/Users/mac/SusFinExercise0202/FinalRawData.xlsx", sheet = 5)

Emission <- read_xlsx("/Users/mac/SusFinExercise0202/FinalRawData.xlsx", sheet = 8)

Figure 1-1: interactive map

Figure 1-1: Global Map of Just Energy Transition Partnership (JETP)

South Africa, Indonesia and Vietnam were the first 3 countries to receive JETP funding, while the Philippines, Senegal, and India are meeting with IPG donor countries

Source: Green Network | Latest Data: March 2023 | Made by Norah Zhang

Show the code
library(leaflet)
library(leaflet.extras)
library(stringr)
library(ggplot2)
library(sf)
library(ggrepel)
library(rnaturalearth)

worldmap_data <- rnaturalearth::ne_countries(returnclass = "sf")
Norway_row <- worldmap_data$name_en == "Norway"
worldmap_data$iso_a3_eh[Norway_row] <- "NOR"

worldmap_JETP <- worldmap_data %>%
  left_join(JETP, by = c("iso_a3_eh" = "Country_Code"))

worldmap_JETP$JETPStatus <- ifelse(is.na(worldmap_JETP$JETPStatus), "N/A", worldmap_JETP$JETPStatus)

worldmap_JETP$JETPStatus <- as.character(worldmap_JETP$JETPStatus)

# Define custom CRS
crs.molvidde <- leafletCRS(
  crsClass="L.Proj.CRS", code='ESRI:53009',
  proj4def= '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs',
  resolutions = c(65536, 32768, 16384, 8192, 4096, 2048))

# Create Leaflet map
leaflet(
  worldmap_JETP,
  options = leafletOptions(
    maxZoom = 5, crs= crs.molvidde, attributionControl = FALSE)) %>%
  addGraticule(style= list(color= '#999', weight= 0.5, opacity= 1)) %>%
  addGraticule(sphere = TRUE,
               style= list(color= '#777', weight= 1, opacity= 0.25)) %>%
  addPolygons(
    label=~paste(subunit, "    ", JETPStatus),
    labelOptions= labelOptions(direction = 'auto'),
    weight=1, color='#ffffff', opacity=1,
    fillColor = colorFactor(
      palette = c("darkolivegreen3","#FDE725FF", "lightblue4","sienna4"),
      domain = worldmap_JETP$JETPStatus)(worldmap_JETP$JETPStatus),
    fillOpacity = 1,
    highlightOptions = highlightOptions(
      color='#000000', weight = 2,
      bringToFront = TRUE, sendToBack = TRUE))

Figure 1-2: two line charts

Show the code
recipient <- c("ZAF","IDN","VNM","IND","SEN","PHL")
recipient_color <- c("South Africa"="chartreuse4", "Indonesia"="chartreuse3", "Vietnam"="darkolivegreen","Philippines" = "chocolate", "Senegal"="chocolate4", "India"="darkorange")

coalemission_JETP <- Emission %>% 
  filter(Code %in% recipient) %>%
  subset(select = c("Entity","Code","Year","Electricity and heat")) %>% 
  rename(Emission = "Electricity and heat") %>% 
  na.omit(Emission)

coalpower_JETP <- powermix %>% 
  filter(Country_Code %in% recipient , Source == "Coal", Year>=1990, Electricity>0) %>% 
  subset(select = c("Country_Name","Country_Code","Year","Electricity")) %>% 
  na.omit(powermix)

coal_JETP <- coalemission_JETP |> 
  left_join(coalpower_JETP, by = c("Code" = "Country_Code","Year"="Year"))

Figure 1-2: JETP recipients’ GHG Emissions from the Power Sector (left) and Electricity Generated from Coal (right)

The JETP’s recipients exhibit a resemblance in coal power generation and electricity sector emission patterns, with the exception of Senegal.

Show the code
library(tidyquant)
library(gridExtra)
library(cowplot)

Emissions <- ggplot(coalemission_JETP, aes(x = Year, y = Emission/1000000, color = Entity, group = Entity)) +
  geom_line() +
  geom_point() +
  theme_minimal() +
  scale_y_log10()+
  scale_color_manual(values = recipient_color)+
  labs(x = "", y = "GHG Emission from Electricity (MtCO2e)") +
  theme(legend.position = "bottom") +
  labs(color="")

Electricity <- ggplot(coalpower_JETP, aes(x = Year, y = Electricity, color = Country_Name, group = Country_Name)) +
  geom_line() +
  geom_point() +
  theme_minimal() +
  scale_color_manual(values = recipient_color)+
  scale_y_log10(breaks = c(0.1, 1, 10, 100, 1000), labels = c("0.1","1", "10", "100", "1000")) +
  labs(x = "", y = "Electricity generated from coal (TWh)") +
  theme(legend.position = "none")

combined_plots <- grid.arrange(Emissions, Electricity, ncol = 2, top = NULL)

Sources: Our World in Data based on CAIT, P Statistical Review of World Energy & Ember | Latest Data: 2021 | Made by Norah Zhang

Figure 2: interactive Sankey Chart

Your raw data should be tidied like this:

Figure 2: Just Energy Transition Partnership Funds to South Africa

The CIF-ACT is the largest funder, with the majority of funding provided in the form of loans.

Show the code
library(networkD3)
library(htmlwidgets)
library(jsonlite)
library(ggplot2)

links <- SA

names(links)[1:2] <- c("source", "target")
nodes <- data.frame(name = unique(c(links$source, links$target)))

links$IDsource <- match(links$source, nodes$name) - 1
links$IDtarget <- match(links$target, nodes$name) - 1


ColourScal ='d3.scaleOrdinal() .range(["#FFA559", "#E86A33", "#FF6000","#DF7857", "#815B5B","#425F57", "#35B779FF", "#6DCD59FF", "#B4DE2CFF", "#FDE725FF"])'

p <- sankeyNetwork(
  Links = links, Nodes = nodes,
  Source = "IDsource", Target = "IDtarget", Value = "Value",
  NodeID = "name", sinksRight = FALSE, colourScale=ColourScal, fontSize = 10)

p <- onRender(
p,
"
  function(el) {
    d3.select(el)
      .selectAll('.node')
      .append('text')
      .attr('x', function(d) { return d.x-3; })
      .attr('y', function(d) { return (d.dy / 2) - 7; })
      .attr('text-anchor', 'end')
      .attr('font-family', 'Arial')
      .attr('font-size', '10px')
      .text(function(d) {
  return '$' + Math.round(d.value).toLocaleString('en-US') + 'M';
});
  }
  "
)
p

Source: UNFCCC COP26 Updates on JETP | Latest Data: 2022 | Made by Norah Zhang

Figure 3: combined scattered and area plots

Figure 3: Foreign Public Energy Investments in South Africa: Project-Based Investments (left) and Total Investment Trend (right))

IBRD, China, the US, and ADB heavily invested in fossil energy projects while Germany and Japan invested more in renewables. Total investment in non-renewables in South Africa is growing faster than that in renewables.

Show the code
library(cowplot)

financialflow_SA <-financialflow %>% 
  filter(`ISO-code` == "ZAF") %>% 
  arrange(Category, Year) %>%
  group_by(Category) %>% 
  mutate(sum_amount = cumsum(`Amount (2020 USD million)`)/1000) %>% 
  ungroup()

scatter_plot <- ggplot(financialflow_SA, aes(x = Year, y = Donor, size = `Amount (2020 USD million)`/1000, color = Category)) +
  geom_point(alpha = 0.8) +
  scale_size_continuous(range = c(1, 10), breaks = c(0.1,1, 2, 3),
             labels = c("$1 million","$1 bliion", "$2 bliion", "$3 billion")) +
    theme_minimal() +
  scale_color_manual(
    values = c("Renewables" = "chartreuse4", "Non-renewables"="darkorange"))+
  labs(x = "", y = "", size = "", color = "")

scatter_plot <- scatter_plot +
  guides(color = guide_legend(nrow = 2),
         size = guide_legend(nrow = 2)) +
  theme(legend.position = "bottom")

area_plot <- ggplot(financialflow_SA, aes(x = Year, y = sum_amount, fill = Category)) +
  geom_area(alpha = 0.3) +
  labs(x = "", y = "Total Investments (Billion USD)", fill = "") +
  scale_fill_manual(values = c("Renewables" = "chartreuse4", "Non-renewables" = "darkorange")) +
  theme_minimal()

area_plot <- area_plot +
  guides(fill = guide_legend(nrow = 2)) +
  theme(legend.position = "bottom")

combined_plots <- grid.arrange(scatter_plot, area_plot, ncol = 2, top = NULL, widths=c(1.5,1))

Source: IRENA Renewable Energy Finance Flows | Latest Data: 2020 | Made by Norah Zhang