Final project-question formation

Research questions

With the oversupply of Solar PVs and growing electricity demand with the global transition to green economy in the future, we would like to explore the supply and demand of Solar PVs from today to 2050. After cleaning the data, we would like to examine the total electricity generation data on Solar PVs and analyze the projected demand for solar PV quantity by three different scenarios: current stated policies scenario, Net Zero Emission by 2050 scenario and 100% Solar Power utilization scenario, assuming the amount of electricity that one solar PV can generate will stay the same in the future.

The questions that we would like to focus on is

1) Carbon Emission reduced solely by Solar PVs

2) The amount of Solar PVs demanded under the energy demand by 2050 under three scenarios

3) The Solar PVs supply vs demand projections

Visualization

library(tidyverse)
Warning: package 'dplyr' was built under R version 4.2.3
Warning: package 'stringr' was built under R version 4.2.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(scales)

Attaching package: 'scales'

The following object is masked from 'package:purrr':

    discard

The following object is masked from 'package:readr':

    col_factor
library(readxl)
library(here)
here() starts at /Users/jiayiding/Desktop/Joy/Johns Hopkins University/MAIR/Spring 2024/Sustainable Finance:Application and Methods/Sustainable Finance final project
library(ggplot2)
library(patchwork)
Warning: package 'patchwork' was built under R version 4.2.3
library(dplyr)

library(readxl)
WEO2023_Free_Dataset <- read_excel("data_raw/WEO2023_Free_Dataset.xlsx", 
    sheet = "World Electricity")
New names:
• `` -> `...9`
• `` -> `...10`
• `Stated Policies Scenario` -> `Stated Policies Scenario...11`
• `Stated Policies Scenario` -> `Stated Policies Scenario...12`
• `Stated Policies Scenario` -> `Stated Policies Scenario...13`
• `Stated Policies Scenario` -> `Stated Policies Scenario...14`
• `Stated Policies Scenario` -> `Stated Policies Scenario...15`
• `Stated Policies Scenario` -> `Stated Policies Scenario...16`
• `Stated Policies Scenario` -> `Stated Policies Scenario...17`
• `` -> `...18`
• `NO` -> `NO...19`
• `NO` -> `NO...20`
• `NO` -> `NO...21`
• `` -> `...22`
• `NO` -> `NO...23`
• `NO` -> `NO...24`
• `` -> `...25`
• `Announced Pledges Scenario` -> `Announced Pledges Scenario...26`
• `Announced Pledges Scenario` -> `Announced Pledges Scenario...27`
• `Announced Pledges Scenario` -> `Announced Pledges Scenario...28`
• `Announced Pledges Scenario` -> `Announced Pledges Scenario...29`
• `Announced Pledges Scenario` -> `Announced Pledges Scenario...30`
• `` -> `...31`
• `NO` -> `NO...32`
• `NO` -> `NO...33`
• `NO` -> `NO...34`
• `` -> `...35`
• `NO` -> `NO...36`
• `NO` -> `NO...37`
• `` -> `...38`
• `Net Zero Emissions by 2050 Scenario` -> `Net Zero Emissions by 2050
  Scenario...39`
• `Net Zero Emissions by 2050 Scenario` -> `Net Zero Emissions by 2050
  Scenario...40`
• `Net Zero Emissions by 2050 Scenario` -> `Net Zero Emissions by 2050
  Scenario...41`
• `Net Zero Emissions by 2050 Scenario` -> `Net Zero Emissions by 2050
  Scenario...42`
• `Net Zero Emissions by 2050 Scenario` -> `Net Zero Emissions by 2050
  Scenario...43`
• `` -> `...44`
• `NO` -> `NO...45`
• `NO` -> `NO...46`
• `NO` -> `NO...47`
• `` -> `...48`
• `NO` -> `NO...49`
• `NO` -> `NO...50`
WEO2023_Clean_Dataset <- WEO2023_Free_Dataset ### Dataset to be tidied
### Make Scenario Columns ###
WEO2023_Clean_Dataset[, c(9, 25, 38)] <- lapply(WEO2023_Clean_Dataset[, c(9, 25, 38)], as.character)
WEO2023_Clean_Dataset[, 9] <- "STEPS"
WEO2023_Clean_Dataset[, 25] <-"APS"
WEO2023_Clean_Dataset[, 38] <-"NZE"
### Make Row 6 (Years) into column names
colnames(WEO2023_Clean_Dataset) <- as.character(unlist(WEO2023_Clean_Dataset[6, ]))
WEO2023_Clean_Dataset <- WEO2023_Clean_Dataset[-(1:6), ]
WEO2023_Clean_Dataset <- WEO2023_Clean_Dataset[ , -c(1, 2, 7, 8)]
WEO2023_Clean_Dataset <- WEO2023_Clean_Dataset[c(6, 1:5, 7:ncol(WEO2023_Clean_Dataset))]
WEO2023_Clean_Dataset <- rbind(colnames(WEO2023_Clean_Dataset), WEO2023_Clean_Dataset)
colnames(WEO2023_Clean_Dataset) <- 1:ncol(WEO2023_Clean_Dataset)
WEO2023_Clean_Dataset <- WEO2023_Clean_Dataset[ , -c(2, 5, 18:20, 31:33, 44:46)]

################################################################################### WEO Shares Dataset ###########################################
### Scenario Names for Shares ###
colnames(WEO2023_Clean_Dataset) <- 1:ncol(WEO2023_Clean_Dataset)
WEO2023_Clean_Dataset[, c(12, 22, 32)] <- lapply(WEO2023_Clean_Dataset[, c(12, 22, 32)], as.character)
WEO2023_Clean_Dataset[, 12] <- "STEPS"
WEO2023_Clean_Dataset[, 22] <-"APS"
WEO2023_Clean_Dataset[, 32] <-"NZE"

WEO_Shares <- WEO2023_Clean_Dataset[ , c(1:3,12:15, 22:25, 32:35)]
colnames(WEO_Shares) <- as.character(unlist(WEO_Shares[1, ]))
WEO_Shares <- WEO_Shares[-c(1, 21:23), ]
# SUBSET DATA & STACK #
# Subset 1
STEPS_Shares <- WEO_Shares[, c(1:7)]
# Subset 2
APS_Shares <- WEO_Shares[, c(1:3, 8:11)]
colnames(APS_Shares)[4:7] <- colnames(STEPS_Shares)[4:7]
# Subset 3
NZE_Shares<- WEO_Shares[, c(1:3, 12:15)]
colnames(NZE_Shares)[4:7] <- colnames(STEPS_Shares)[4:7]
# Stack Subsets 1-3
stacked_data <- rbind(STEPS_Shares, APS_Shares, NZE_Shares)
colnames(stacked_data)[2:4] <- c("Type", "Description", "Scenario")
### PIVOT DATA ####
WEO_Shares_long <- stacked_data[,-1] %>%
  pivot_longer(cols = 4:6, names_to = "Year", values_to = "Shares")

################################################################################
################# WEO Values Dataset ###########################################
WEO_Values <- WEO2023_Clean_Dataset[ , -c(12:15, 22:25, 32:35)]
new_order <- c(1:3, 5:6, 4, 7:ncol(WEO_Values))
WEO_Values <- WEO_Values[, new_order]
colnames(WEO_Values) <- 1:ncol(WEO_Values)
colnames(WEO_Values) <- as.character(unlist(WEO_Values[1, ]))
WEO_Values <- WEO_Values[-c(1,21:23), ]

### STACKED DATA######
base_segment <- WEO_Values[, 1:11] # Columns 1 to 11
#Prepare the additional segments for stacking
# Including columns 1 to 5 with both segments 12:17 and 18:23
segment_12_17 <- WEO_Values[, c(1:5, 12:17)]
segment_18_23 <- WEO_Values[, c(1:5, 18:23)]
colnames(segment_12_17)[6:11] <- colnames(base_segment)[6:11]
colnames(segment_18_23)[6:11] <- colnames(base_segment)[6:11]
# Step 3: Stack the segments
stacked_values<- rbind(base_segment, segment_12_17, segment_18_23)
colnames(stacked_values)[2:3] <- c("Type", "Description")
new_order <- c(2:3, 6, 4:5, 7:ncol(stacked_values))
stacked_values <- stacked_values[, new_order]
### PIVOT DATA ####
WEO_Values_long <- stacked_values %>%
  pivot_longer(cols = 4:10, names_to = "Year", values_to = "Values")

WEO_analysis <- WEO_Values_long|>
  filter(Type == "Total"|Type == "Solar PV")|>
  filter(STEPS != "APS")|>
  filter(Description == "Electrical capacity")

WEO_Values_Solar <- WEO_Values_long %>%
  filter(Type=="Solar PV") %>%
  filter(Description == "Electricity generation") %>%
  mutate(Year = as.numeric(Year)) %>%
  mutate(Values = as.numeric(Values)) %>%
  select(-Description, -Type)

ggplot(WEO_Values_Solar) +
  aes(x = Year, y = Values, colour = STEPS) +
  geom_line() +
  scale_color_hue(direction = 1) +
  labs(
    title = "Solar PV Electricity Generation by Scenario,
    2020-2050"
  ) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    legend.position = "bottom"  # Positioning legend at the bottom
  ) +
  scale_x_continuous(breaks = seq(2010, 2050, 10)) +
  facet_wrap(vars(STEPS))