# 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>
1.1 Tidying the headers
sheet_header_processed <- sheet_header |># transpose the datat() |># turn it back into a tibbleas_tibble() |>rename(scenario = V1, year = V2) |># fill scenario downfill(scenario) |>#insert "Current" at topreplace_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`.
sheet_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
combined_data <- mineral_info_long |>left_join(sheet_headers_and_col_names, by =join_by(mineral_info_col_names)) |># filter out what were empty columns (where years are NA) filter(!is.na(year)) |># case_when is supercharged if elsemutate(unit =case_when( indicator =="Total EV"~"Number",.default ="kiloton" ),# convert the year column from character to numericyear =as.integer(year) ) |>select(mineral_demand, indicator, scenario, unit, year, value)combined_data
mineral_info_col_names <-names(mineral_info)mineral_info_long <- mineral_info |>rename(indicator =`...1`) |>pivot_longer(cols =-indicator,names_to ="mineral_info_col_names") |>add_column(mineral_demand)combined_data <- mineral_info_long |>left_join(sheet_headers_and_col_names, by =join_by(mineral_info_col_names)) |># filter out what were empty columns (where years are NA) filter(!is.na(year)) |># case_when is supercharged if elsemutate(unit =case_when( indicator =="Total EV"~"Number",.default ="kiloton" ),# convert the year column from character to numericyear =as.integer(year) ) |>select(mineral_demand, indicator, scenario, unit, year, value)combined_data
Part 2: Use the tidied dataset to have 5 compelling data visualizations
Trend of Copper and Cobalt Demand Over Time for Each Scenario
mineral_demand <- final_iea_minerals_EV_table# filter out the data for Copper and Cobalt demand onlycopper_cobalt_demand <- mineral_demand %>%filter(indicator %in%c("Copper", "Cobalt"))# the trend of Copper and Cobalt demand over time for each scenarioggplot(copper_cobalt_demand, aes(x = year, y = value, color = scenario)) +geom_line() +facet_wrap(~indicator, scales ="free_y", ncol =1) +labs(title ="Trend of Copper and Cobalt Demand Over Time for Each Scenario",x ="Year", y ="Demand (in kilotones)") +theme_minimal() +theme(legend.position ="bottom")
Comparison of Demand in Different Scenarios in three different year:2025, 2030, and 2040
mineral_demand <- final_iea_minerals_EV_tablekey_milestone_demand <- mineral_demand %>%filter(indicator %in%c("Copper", "Cobalt")) %>%filter(year %in%c(2025, 2030, 2040))# Plotting the comparison of demand in different scenarios at key milestonesggplot(key_milestone_demand, aes(x =factor(year), y = value, fill = scenario)) +geom_bar(stat ="identity", position ="dodge") +facet_wrap(~indicator, scales ="free_y") +labs(title ="Comparison of Copper and Cobalt Demand in Different Scenarios at Key Milestones",x ="Year", y ="Demand (in kilotonnes)") +scale_fill_brewer(palette ="Set1") +theme_minimal() +theme(legend.title =element_blank(), legend.position ="bottom")
Comparative Analysis that analyze the Copper to Cobalt Demand Ratio Over Time
# Filter for Copper and Cobalt and calculate the ratiocopper_cobalt_ratio <- mineral_demand %>%filter(indicator %in%c("Copper", "Cobalt")) %>%group_by(year, scenario) %>%summarise(CopperDemand =sum(value[indicator =="Copper"]),CobaltDemand =sum(value[indicator =="Cobalt"]),Ratio = CopperDemand / CobaltDemand ) %>%ungroup()
`summarise()` has grouped output by 'year'. You can override using the
`.groups` argument.
# Visualizing the Copper to Cobalt Demand Ratio Over Timeggplot(copper_cobalt_ratio, aes(x = year, y = Ratio, color = scenario)) +geom_line() +geom_point() +labs(title ="Copper to Cobalt Demand Ratio Over Time",x ="Year", y ="Copper to Cobalt Demand Ratio",color ="Scenario") +theme_minimal() +theme(legend.position ="bottom")