Final project

Step 1: Make a plan

What data are you starting with?

IEA Net-Zero Emissions by 2050 Roadmap scenario projection data

The projected Solar PV electricity generation by country and region.

If you are going to be joining datasets, what variables will you use to join those datasets? I will be using countries to join the dataset

What data do you need to pivot from wide format to long format? What data types should each variable be (dates, numeric, character, factor)? Character.

Step 2: Data cleaning

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(readxl)
library(here)
here() starts at /Users/jiayiding/Desktop/Joy/Johns Hopkins University/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)

path_to_sheet <- here("data_raw", "WEO2023_Free_Dataset.xlsx")
path_to_sheet
[1] "/Users/jiayiding/Desktop/Joy/Johns Hopkins University/Spring 2024/Sustainable Finance:Application and Methods/Sustainable Finance final project/data_raw/WEO2023_Free_Dataset.xlsx"
solar_pv_sheet <- partial(
  .f = read_excel,
  path = path_to_sheet,
  sheet = "Solar PV generation (TWh)",
  col_names = FALSE
)

sheet_header <- solar_pv_sheet(range = "J7:S9")
New names:
• `` -> `...1`
• `` -> `...2`
• `` -> `...3`
• `` -> `...4`
• `` -> `...5`
• `` -> `...6`
• `` -> `...7`
• `` -> `...8`
• `` -> `...9`
• `` -> `...10`
sheet_header_processed <- sheet_header |> 
  t() |>
  as_tibble() |>
  select(-V2) |> 
  rename(scenario = V1, year = V3) |>
  fill(scenario)
Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if
`.name_repair` is omitted as of tibble 2.0.0.
ℹ Using compatibility `.name_repair`.
country_info <- solar_pv_sheet(range = "J10:S25")
New names:
• `` -> `...1`
• `` -> `...2`
• `` -> `...3`
• `` -> `...4`
• `` -> `...5`
• `` -> `...6`
• `` -> `...7`
• `` -> `...8`
• `` -> `...9`
• `` -> `...10`
country_info_names <- names(country_info)

sheet_headers_and_col_names <- sheet_header_processed |> 
  add_column(country_info_names = country_info_names)

country_info_long <- country_info |>
  rename(country_name = `...1`) |>
  pivot_longer(cols = -country_name,
               names_to = "country_info_names")

combined_data <- country_info_long |> 
  left_join(sheet_headers_and_col_names, by = join_by(country_info_names)) |> 
  filter(!is.na(year)) |> 
  mutate(year = as.integer(year)) |> 
  select(country_name, scenario, year, value)

combined_data
# A tibble: 112 × 4
   country_name  scenario                year    value
   <chr>         <chr>                  <int>    <dbl>
 1 World         "Historical"            2010    32.0 
 2 World         "Historical"            2021  1023.  
 3 World         "Historical"            2022  1291.  
 4 World         "Stated\r\nPolicies"    2030  5405.  
 5 World         "Stated\r\nPolicies"    2050 17220.  
 6 World         "Announced\r\nPledges"  2030  6390.  
 7 World         "Announced\r\nPledges"  2050 24297.  
 8 North America "Historical"            2010     3.35
 9 North America "Historical"            2021   167.  
10 North America "Historical"            2022   203.  
# ℹ 102 more rows