file_path1 <- "C:/Users/mikha/Downloads/mineral industry trends and salient statistics/MCS2024_T5_Critical_Minerals_Salient.csv"
file_path2 <- "C:/Users/mikha/Downloads/mineral industry trends and salient statistics/MCS2024_Fig2_Net_Import_Reliance.csv"
data1 <- read.csv(file_path1)
data2 <- read.csv(file_path2)
data2 <- rename(data2, "Critical_mineral" = "Commodity")
data2$Critical_mineral <- data2$Critical_mineral %>%
tolower() %>%
str_to_title()
data1$Critical_mineral <- data1$Critical_mineral %>%
tolower() %>%
str_to_title()
df <- merge(data1, data2 , by = "Critical_mineral")
#Critical Mineral amount by Country
gg <- ggplot(data = df, aes(x = "", y = ..count.., fill = Primary_import_source)) +
geom_bar(position = "dodge", color = "black") +
labs(x = "Critical Mineral", y = "Count", title = "Primary Import Source for Critical Minerals") +
theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) # Hide x-axis labels and ticks
p <- ggplotly(gg, tooltip = c("Critical_mineral", "Primary_import_source", "y"))
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.
## ℹ The deprecated feature was likely used in the ggplot2 package.
## Please report the issue at <https://github.com/tidyverse/ggplot2/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
# Update layout
p <- p %>% layout(
title = "Primary Import Source for Critical Minerals",
hoverlabel = list(bgcolor = "white"),
hovermode = "x",
updatemenus = list(
list(
buttons = list(
list(
args = list(type = "treemap"),
label = "Tree Map",
method = "restyle"
)
),
direction = "down",
pad = list(r = 10, t = 10),
showactive = TRUE,
x = 0.1,
xanchor = "left",
y = 1.1,
yanchor = "top"
)
)
)
# Print the plotly object
p
Mapping minerals by source
world_map <- map_data("world")
ggplot() +
geom_polygon(data = world_map, aes(x = long, y = lat, group = group), fill = "lightgrey") + # Basemap
geom_point(data = geocoded_data, aes(x = geocode_result$lon, y = geocode_result$lat, color = Critical_mineral)) + # Data points
labs(title = "Map of Primary Import Source and Critical Mineral", x = "Longitude", y = "Latitude") + # Labels
theme_minimal()
classify_country <- function(country) {
allies <- c("Canada", "United Kingdom", "Germany", "Japan", "South Korea", "Australia")
competitors <- c("China", "European Union", "Russia")
if (country %in% allies) {
return("Ally")
} else if (country %in% competitors) {
return("Competitor")
} else {
return("Neutral")
}
}
geocoded_data$Country_Classification <- sapply(geocoded_data$Primary_import_source, classify_country)
world_map <- map_data("world")
ggplot() +
geom_polygon(data = world_map, aes(x = long, y = lat, group = group), fill = "lightgrey") +
geom_point(data = geocoded_data, aes(x = geocode_result$lon, y = geocode_result$lat, color = Country_Classification)) + # Data points
labs(title = "Map of Primary Import Source and Critical Mineral", x = "Longitude", y = "Latitude") +
theme_minimal()
#Conclusion
As we can see that most of our imports based on materials come from China which is our competitor and NET import reliance is heavily dependent from them. The data underscores the concerning reliance on critical imports from China, a competitor, which poses risks to national security, economic stability, and supply chain resilience. Diversifying import sources and investing in domestic production are imperative to mitigate vulnerabilities and enhance strategic independence.