Prepwork

options(repos = c(CRAN = "https://cloud.r-project.org/"))
install.packages("tidyverse")
Installing package into 'C:/Users/owner/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
package 'tidyverse' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\owner\AppData\Local\Temp\RtmpovrtGe\downloaded_packages
install.packages("janitor")
Installing package into 'C:/Users/owner/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
package 'janitor' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\owner\AppData\Local\Temp\RtmpovrtGe\downloaded_packages
install.packages("countrycode")
Installing package into 'C:/Users/owner/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
package 'countrycode' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\owner\AppData\Local\Temp\RtmpovrtGe\downloaded_packages
install.packages("hrbrthemes")
Installing package into 'C:/Users/owner/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
package 'hrbrthemes' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\owner\AppData\Local\Temp\RtmpovrtGe\downloaded_packages
install.packages("viridis")
Installing package into 'C:/Users/owner/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
package 'viridis' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\owner\AppData\Local\Temp\RtmpovrtGe\downloaded_packages
install.packages("here")
Installing package into 'C:/Users/owner/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
package 'here' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\owner\AppData\Local\Temp\RtmpovrtGe\downloaded_packages
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ 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(janitor) 

Attaching package: 'janitor'

The following objects are masked from 'package:stats':

    chisq.test, fisher.test
library(countrycode)
library(ggplot2)
library(hrbrthemes)
NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
      Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
      if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
library(viridis)
Loading required package: viridisLite
library(readxl)
library(here)
here() starts at C:/Users/owner/Desktop/Sustainable Finance/R/HW6

Data processing

path_to_sheet <- here("raw-data", "CM_Data_Explorer.xlsx")
path_to_sheet
[1] "C:/Users/owner/Desktop/Sustainable Finance/R/HW6/raw-data/CM_Data_Explorer.xlsx"
EV_sheet <- partial(
  .f = read_excel,
  path = path_to_sheet,
  sheet = "2.3 EV",
  col_names = FALSE
)

EV_sheet()
New names:
• `` -> `...1`
• `` -> `...2`
• `` -> `...3`
• `` -> `...4`
• `` -> `...5`
• `` -> `...6`
• `` -> `...7`
• `` -> `...8`
• `` -> `...9`
• `` -> `...10`
• `` -> `...11`
• `` -> `...12`
• `` -> `...13`
• `` -> `...14`
• `` -> `...15`
• `` -> `...16`
• `` -> `...17`
• `` -> `...18`
• `` -> `...19`
• `` -> `...20`
• `` -> `...21`
• `` -> `...22`
• `` -> `...23`
# A tibble: 93 × 23
   ...1          ...2 ...3  ...4    ...5   ...6   ...7   ...8   ...9 ...10 ...11
   <chr>        <dbl> <lgl> <chr>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl> <lgl> <chr>
 1 Mineral de…   NA   NA    <NA>    NA     NA     NA     NA     NA   NA    <NA> 
 2 <NA>          NA   NA    <NA>    NA     NA     NA     NA     NA   NA    <NA> 
 3 <NA>          NA   NA    Stat…   NA     NA     NA     NA     NA   NA    Anno…
 4 <NA>        2022   NA    2025  2030   2035   2040   2045   2050   NA    2025 
 5 <NA>          NA   NA    <NA>    NA     NA     NA     NA     NA   NA    <NA> 
 6 Constraine…   NA   NA    <NA>    NA     NA     NA     NA     NA   NA    <NA> 
 7 Copper       381.  NA    616.… 1389.  1736.  2233.  2418.  2313.  NA    731.…
 8 Cobalt        63.5 NA    61.2…   38.0   29.1   35.4   40.9   47.4 NA    71.1…
 9 Graphite     557.  NA    935.… 1590.  1782.  1691.  1492.  1077.  NA    1100…
10 Lithium       69.6 NA    122.…  219.   307.   407.   450.   413.  NA    144.…
# ℹ 83 more rows
# ℹ 12 more variables: ...12 <dbl>, ...13 <dbl>, ...14 <dbl>, ...15 <dbl>,
#   ...16 <dbl>, ...17 <lgl>, ...18 <chr>, ...19 <dbl>, ...20 <dbl>,
#   ...21 <dbl>, ...22 <dbl>, ...23 <dbl>
sheet_header <- EV_sheet(range = "A4:W5")
New names:
• `` -> `...1`
• `` -> `...2`
• `` -> `...3`
• `` -> `...4`
• `` -> `...5`
• `` -> `...6`
• `` -> `...7`
• `` -> `...8`
• `` -> `...9`
• `` -> `...10`
• `` -> `...11`
• `` -> `...12`
• `` -> `...13`
• `` -> `...14`
• `` -> `...15`
• `` -> `...16`
• `` -> `...17`
• `` -> `...18`
• `` -> `...19`
• `` -> `...20`
• `` -> `...21`
• `` -> `...22`
• `` -> `...23`
sheet_header
# A tibble: 2 × 23
  ...1   ...2 ...3  ...4    ...5  ...6  ...7  ...8  ...9 ...10 ...11 ...12 ...13
  <lgl> <dbl> <lgl> <chr>  <dbl> <dbl> <dbl> <dbl> <dbl> <lgl> <chr> <dbl> <dbl>
1 NA       NA NA    State…    NA    NA    NA    NA    NA NA    Anno…    NA    NA
2 NA     2022 NA    2025    2030  2035  2040  2045  2050 NA    2025   2030  2035
# ℹ 10 more variables: ...14 <dbl>, ...15 <dbl>, ...16 <dbl>, ...17 <lgl>,
#   ...18 <chr>, ...19 <dbl>, ...20 <dbl>, ...21 <dbl>, ...22 <dbl>,
#   ...23 <dbl>
header_processed <- sheet_header |> 
  t() |>
  as_tibble() |>
  rename(scenario = V1, year = V2) |>
  fill(scenario) |>
  replace_na(list(scenario = "Current Year"))
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`.
header_processed
# A tibble: 23 × 2
   scenario                 year 
   <chr>                    <chr>
 1 Current Year             <NA> 
 2 Current Year             2022 
 3 Current Year             <NA> 
 4 Stated policies scenario 2025 
 5 Stated policies scenario 2030 
 6 Stated policies scenario 2035 
 7 Stated policies scenario 2040 
 8 Stated policies scenario 2045 
 9 Stated policies scenario 2050 
10 Stated policies scenario <NA> 
# ℹ 13 more rows
EV_name <- EV_sheet(range = "A7") |> 
  pull()
New names:
• `` -> `...1`
EV_name
[1] "Constrained nickel supply"
EV_info <- EV_sheet(range = "A8:W19")
New names:
• `` -> `...1`
• `` -> `...2`
• `` -> `...3`
• `` -> `...4`
• `` -> `...5`
• `` -> `...6`
• `` -> `...7`
• `` -> `...8`
• `` -> `...9`
• `` -> `...10`
• `` -> `...11`
• `` -> `...12`
• `` -> `...13`
• `` -> `...14`
• `` -> `...15`
• `` -> `...16`
• `` -> `...17`
• `` -> `...18`
• `` -> `...19`
• `` -> `...20`
• `` -> `...21`
• `` -> `...22`
• `` -> `...23`
EV_info
# A tibble: 12 × 23
   ...1         ...2 ...3     ...4    ...5    ...6    ...7    ...8    ...9 ...10
   <chr>       <dbl> <lgl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl> <lgl>
 1 Copper    3.81e+2 NA    6.17e+2 1.39e+3 1.74e+3 2.23e+3 2.42e+3 2.31e+3 NA   
 2 Cobalt    6.35e+1 NA    6.12e+1 3.80e+1 2.91e+1 3.54e+1 4.09e+1 4.74e+1 NA   
 3 Graphite  5.57e+2 NA    9.36e+2 1.59e+3 1.78e+3 1.69e+3 1.49e+3 1.08e+3 NA   
 4 Lithium   6.96e+1 NA    1.23e+2 2.19e+2 3.07e+2 4.07e+2 4.50e+2 4.13e+2 NA   
 5 Manganese 7.45e+1 NA    5.39e+1 1.56e+2 3.36e+2 5.33e+2 7.12e+2 8.58e+2 NA   
 6 Nickel    3.13e+2 NA    5.54e+2 5.13e+2 5.89e+2 6.30e+2 6.92e+2 6.88e+2 NA   
 7 Silicon   8.70e+0 NA    4.05e+1 1.39e+2 2.24e+2 3.52e+2 3.74e+2 3.73e+2 NA   
 8 Neodymium 3.96e+0 NA    7.25e+0 1.22e+1 1.51e+1 1.88e+1 2.18e+1 2.29e+1 NA   
 9 Dysprosi… 4.13e-1 NA    7.41e-1 1.21e+0 1.48e+0 1.84e+0 2.13e+0 2.23e+0 NA   
10 Praseody… 5.94e-1 NA    1.09e+0 1.83e+0 2.27e+0 2.83e+0 3.27e+0 3.43e+0 NA   
11 Terbium   8.06e-2 NA    1.48e-1 2.52e-1 3.14e-1 3.91e-1 4.52e-1 4.74e-1 NA   
12 Total EV  1.47e+3 NA    2.39e+3 4.06e+3 5.02e+3 5.91e+3 6.21e+3 5.80e+3 NA   
# ℹ 13 more variables: ...11 <dbl>, ...12 <dbl>, ...13 <dbl>, ...14 <dbl>,
#   ...15 <dbl>, ...16 <dbl>, ...17 <lgl>, ...18 <dbl>, ...19 <dbl>,
#   ...20 <dbl>, ...21 <dbl>, ...22 <dbl>, ...23 <dbl>
EV_info_col_names <- names(EV_info)

sheet_headers_and_col_names <- header_processed |> 
  add_column(EV_info_col_names = EV_info_col_names)

EV_info_long <- EV_info |> 
  rename(indicator = `...1`) |> 
  pivot_longer(cols = -indicator,
               names_to = "EV_info_col_names") |> 
  add_column(EV_name)

combined_data <- EV_info_long |> 
  left_join(sheet_headers_and_col_names, by = join_by(EV_info_col_names)) |> 
  filter(!is.na(year)) |> 
  mutate(unit = "kiloton",
         year = as.integer(year)
  ) |> 
  select(EV_name, indicator, scenario, unit, year, value)

combined_data
# A tibble: 228 × 6
   EV_name                   indicator scenario                unit   year value
   <chr>                     <chr>     <chr>                   <chr> <int> <dbl>
 1 Constrained nickel supply Copper    Current Year            kilo…  2022  381.
 2 Constrained nickel supply Copper    Stated policies scenar… kilo…  2025  617.
 3 Constrained nickel supply Copper    Stated policies scenar… kilo…  2030 1389.
 4 Constrained nickel supply Copper    Stated policies scenar… kilo…  2035 1736.
 5 Constrained nickel supply Copper    Stated policies scenar… kilo…  2040 2233.
 6 Constrained nickel supply Copper    Stated policies scenar… kilo…  2045 2418.
 7 Constrained nickel supply Copper    Stated policies scenar… kilo…  2050 2313.
 8 Constrained nickel supply Copper    Announced pledges scen… kilo…  2025  732.
 9 Constrained nickel supply Copper    Announced pledges scen… kilo…  2030 2113.
10 Constrained nickel supply Copper    Announced pledges scen… kilo…  2035 3587.
# ℹ 218 more rows
read_EV_table <-
  function(EV_name_range, EV_info_range) {
    EV_name <-
      EV_sheet(range = EV_name_range) |>
      pull()
    
    EV_info <- EV_sheet(range = EV_info_range)
    EV_info_col_names <- names(EV_info)
    EV_info_long <- EV_info |>
      rename(indicator = `...1`) |>
      pivot_longer(cols = -indicator,
                   names_to = "EV_info_col_names") |>
      add_column(EV_name)
    
    combined_data <- EV_info_long |>
      left_join(sheet_headers_and_col_names, by = join_by(EV_info_col_names)) |>
      filter(!is.na(year)) |>
      mutate(
        year = as.integer(year)
      ) |>
      select(EV_name, indicator, scenario, year, value)
    combined_data
  }

nickel_supply_table <- read_EV_table(
  EV_name_range = "A7",
  EV_info_range = "A8:W19"
)
New names:
New names:
• `` -> `...1`
wider_use_of_silicon_rich_anodes_table <- read_EV_table(
  EV_name_range = "A22",
  EV_info_range = "A23:W34"
)
New names:
New names:
• `` -> `...1`
faster_uptake_of_solid_state_batteries_table <- read_EV_table(
  EV_name_range = "A37",
  EV_info_range = "A38:W49"
)
New names:
New names:
• `` -> `...1`
lower_battery_sizes_table <- read_EV_table(
  EV_name_range = "A52",
  EV_info_range = "A53:W64"
)
New names:
New names:
• `` -> `...1`
limited_battery_size_reduction_table <- read_EV_table(
  EV_name_range = "A67",
  EV_info_range = "A68:W79"
)
New names:
New names:
• `` -> `...1`
STEPS_Base_case_table <- read_EV_table(
  EV_name_range = "A82",
  EV_info_range = "A83:W94"
)
New names:
New names:
• `` -> `...1`
final_EV_table <- nickel_supply_table |> 
  bind_rows(wider_use_of_silicon_rich_anodes_table) |>
  bind_rows(faster_uptake_of_solid_state_batteries_table) |>
  bind_rows(lower_battery_sizes_table) |>
  bind_rows(limited_battery_size_reduction_table) |>
  bind_rows(STEPS_Base_case_table)

final_EV_table
# A tibble: 1,368 × 5
   EV_name                   indicator scenario                    year value
   <chr>                     <chr>     <chr>                      <int> <dbl>
 1 Constrained nickel supply Copper    Current Year                2022  381.
 2 Constrained nickel supply Copper    Stated policies scenario    2025  617.
 3 Constrained nickel supply Copper    Stated policies scenario    2030 1389.
 4 Constrained nickel supply Copper    Stated policies scenario    2035 1736.
 5 Constrained nickel supply Copper    Stated policies scenario    2040 2233.
 6 Constrained nickel supply Copper    Stated policies scenario    2045 2418.
 7 Constrained nickel supply Copper    Stated policies scenario    2050 2313.
 8 Constrained nickel supply Copper    Announced pledges scenario  2025  732.
 9 Constrained nickel supply Copper    Announced pledges scenario  2030 2113.
10 Constrained nickel supply Copper    Announced pledges scenario  2035 3587.
# ℹ 1,358 more rows
write_csv(final_EV_table,here("data", "iea_mineral_demand_for_EV.csv"))
cleaned_data <- here("data", "iea_mineral_demand_for_EV.csv") |> 
  read_csv()
Rows: 1368 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): EV_name, indicator, scenario
dbl (2): year, value

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
cleaned_data
# A tibble: 1,368 × 5
   EV_name                   indicator scenario                    year value
   <chr>                     <chr>     <chr>                      <dbl> <dbl>
 1 Constrained nickel supply Copper    Current Year                2022  381.
 2 Constrained nickel supply Copper    Stated policies scenario    2025  617.
 3 Constrained nickel supply Copper    Stated policies scenario    2030 1389.
 4 Constrained nickel supply Copper    Stated policies scenario    2035 1736.
 5 Constrained nickel supply Copper    Stated policies scenario    2040 2233.
 6 Constrained nickel supply Copper    Stated policies scenario    2045 2418.
 7 Constrained nickel supply Copper    Stated policies scenario    2050 2313.
 8 Constrained nickel supply Copper    Announced pledges scenario  2025  732.
 9 Constrained nickel supply Copper    Announced pledges scenario  2030 2113.
10 Constrained nickel supply Copper    Announced pledges scenario  2035 3587.
# ℹ 1,358 more rows
unique(cleaned_data$EV_name)
[1] "Constrained nickel supply"             
[2] "Wider use of silicon-rich anodes"      
[3] "Faster uptake of solid state batteries"
[4] "Lower battery sizes"                   
[5] "Limited battery size reduction"        
[6] "STEPS - Base case"                     

Visualization

#1

# 1
cleaned_data |> 
  filter(EV_name == "STEPS - Base case") |> 
  filter(scenario =="Net Zero Emissions by 2050 scenario") |>
  filter(indicator !="Total EV") |>
  
  ggplot(aes(year, value, fill=indicator)) +
  geom_col(position = "stack") +
  # facet_wrap(~scenario)+
  labs(
      x="Year",
      y="Weight (kT)",
       title="Critical mineral demand increases dramatically",
       # subtitle="Net Zero Emissions by 2050 scenario",
       caption="Data: IEA") + 
  theme_ft_rc()
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database

Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database

Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

#2

cleaned_data |> 
  # filter(EV_name == "STEPS - Base case") |> 
  filter(scenario =="Net Zero Emissions by 2050 scenario") |>
  filter(indicator =="Total EV") |>
  
  ggplot(aes(x=year, y=value, color=EV_name)) +
  geom_line() +
  # facet_wrap(~EV_name)+
  labs(
    x="Year",
    y="Total Critical Minerals Weight (kT)",
    title="EV technology changes total critical mineral demand",
    subtitle="Under Net Zero Emissions by 2050 scenario",
    caption="Data: IEA") + 
  theme_ft_rc()
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

#3

cleaned_data
# A tibble: 1,368 × 5
   EV_name                   indicator scenario                    year value
   <chr>                     <chr>     <chr>                      <dbl> <dbl>
 1 Constrained nickel supply Copper    Current Year                2022  381.
 2 Constrained nickel supply Copper    Stated policies scenario    2025  617.
 3 Constrained nickel supply Copper    Stated policies scenario    2030 1389.
 4 Constrained nickel supply Copper    Stated policies scenario    2035 1736.
 5 Constrained nickel supply Copper    Stated policies scenario    2040 2233.
 6 Constrained nickel supply Copper    Stated policies scenario    2045 2418.
 7 Constrained nickel supply Copper    Stated policies scenario    2050 2313.
 8 Constrained nickel supply Copper    Announced pledges scenario  2025  732.
 9 Constrained nickel supply Copper    Announced pledges scenario  2030 2113.
10 Constrained nickel supply Copper    Announced pledges scenario  2035 3587.
# ℹ 1,358 more rows
unique(cleaned_data$indicator)
 [1] "Copper"       "Cobalt"       "Graphite"     "Lithium"      "Manganese"   
 [6] "Nickel"       "Silicon"      "Neodymium"    "Dysprosium"   "Praseodymium"
[11] "Terbium"      "Total EV"    
unique(cleaned_data$scenario)
[1] "Current Year"                        "Stated policies scenario"           
[3] "Announced pledges scenario"          "Net Zero Emissions by 2050 scenario"
update_geom_font_defaults(font_rc_light)

cleaned_data |> 
  filter(indicator=="Copper") |> 
  filter(scenario !="Current Year") |> 
  ggplot(aes(scenario, value)) +
  geom_col() +
  coord_flip() +
  labs(x="Copper demand", y="Scenarios",
       title="Net Zero scenario demands 3X stated policies copper demand for EV productino",
       # subtitle="A plot that is only useful for demonstration purposes, esp since you'd never\nreally want direct labels and axis labels",
       caption="Data: IEA") + 
  theme_ipsum_rc(grid="X")
Warning: Removed 12 rows containing missing values (`position_stack()`).
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

#4

cleaned_data |> 
  filter(indicator %in% c("Nickel", "Copper", "Graphite"))  |> 
  filter(scenario %in% "Net Zero Emissions by 2050 scenario")  |> 
  ggplot() +
  aes(x = EV_name, fill = indicator, weight = value) +
  geom_bar() +
  scale_fill_hue(direction = 1) +
  labs(
    x = "Conditions",
    y = "Demand (kT)",
    title = "Demand of top 3 critical minerals for EV production",
    fill = "Mineral type"
  ) +
  coord_flip() +
  theme_ipsum_rc() +
  facet_wrap(vars(year))
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

#5

cleaned_data
# A tibble: 1,368 × 5
   EV_name                   indicator scenario                    year value
   <chr>                     <chr>     <chr>                      <dbl> <dbl>
 1 Constrained nickel supply Copper    Current Year                2022  381.
 2 Constrained nickel supply Copper    Stated policies scenario    2025  617.
 3 Constrained nickel supply Copper    Stated policies scenario    2030 1389.
 4 Constrained nickel supply Copper    Stated policies scenario    2035 1736.
 5 Constrained nickel supply Copper    Stated policies scenario    2040 2233.
 6 Constrained nickel supply Copper    Stated policies scenario    2045 2418.
 7 Constrained nickel supply Copper    Stated policies scenario    2050 2313.
 8 Constrained nickel supply Copper    Announced pledges scenario  2025  732.
 9 Constrained nickel supply Copper    Announced pledges scenario  2030 2113.
10 Constrained nickel supply Copper    Announced pledges scenario  2035 3587.
# ℹ 1,358 more rows
cleaned_data |> 
  filter(indicator %in% c("Nickel")) |> 
  filter(scenario == "Net Zero Emissions by 2050 scenario") |> 
  filter(!is.na(value)) |> 
  ggplot() +
  aes(
    x = year,
    y = value,
    fill = indicator,
    colour = indicator
  ) +
  geom_point(shape = "circle", size = 1.5) +
  geom_smooth(span = 0.75) +
  scale_fill_brewer(palette = "Accent", direction = 1) +
  scale_color_brewer(palette = "Accent", direction = 1) +
  labs(
    x = "Year",
    y = "Demand (kt)",
    title = "Nickel demand project averaged across conditions under Net Zero scenario",
    subtitle = "Demand to peak after 2035 and remains steady over 3000kT"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(face = "bold"),
    axis.title.y = element_text(face = "bold"),
    axis.title.x = element_text(face = "bold")
  ) +
  facet_wrap(vars(scenario))
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'