# Load in libraries
library(jpeg)
library(png)
library(tidyverse)
library(sf)
library(patchwork)
library(ggstream)
#............................load Data...........................
# Loading in Carbon Mapper data
# Plumes by year
plumes_2016 <- read.csv(here::here("Posts", "plume_infographic","data", "plume_yearly", "export_2016_2017", "export_2016-01-01_2017-01-01.csv"))
plumes_2017 <- read.csv(here::here("Posts", "plume_infographic","data", "plume_yearly", "export_2017_2018", "export_2017-01-01_2018-01-01.csv"))
plumes_2018 <- read.csv(here::here("Posts", "plume_infographic","data", "plume_yearly", "export_2018_2019", "export_2018-01-01_2019-01-01.csv"))
plumes_2019 <- read.csv(here::here("Posts", "plume_infographic","data", "plume_yearly", "export_2019_2020", "export_2019-01-01_2020-01-01.csv"))
plumes_2020 <- read.csv(here::here("Posts", "plume_infographic","data", "plume_yearly", "export_2020_2021", "export_2020-01-01_2021-01-01.csv"))
plumes_2021 <- read.csv(here::here("Posts", "plume_infographic","data", "plume_yearly", "export_2021_2022", "export_2021-01-01_2022-01-01.csv"))
plumes_2022 <- read.csv(here::here("Posts", "plume_infographic","data", "plume_yearly", "export_2022_2023", "export_2022-01-01_2023-01-01.csv"))
plumes_2023 <- read.csv(here::here("Posts", "plume_infographic","data", "plume_yearly", "export_2023_2024", "export_2023-01-01_2024-01-01.csv"))
plumes_2024 <- read.csv(here::here("Posts", "plume_infographic","data", "plume_yearly", "export_2024_2025", "export_2024-01-01_2025-01-01.csv"))
plumes_2025 <- read.csv(here::here("Posts", "plume_infographic","data", "plume_yearly", "export_2025_2025", "export_2025-01-01_2025-10-01.csv"))
# Combines the years into `plumes`
plumes <- rbind(plumes_2016, plumes_2017, plumes_2018, plumes_2019, plumes_2020, plumes_2021, plumes_2022, plumes_2023, plumes_2024, plumes_2025)
# Make plumes spatial
plumes <- st_as_sf(plumes, coords = c('plume_longitude', 'plume_latitude'), crs = 'EPSG:4326')
# Add country data
counties <- spData::world
# JOIN Plume + Country data
plumes_country <- st_join(counties, plumes)
# Create color palettes
gas_pal <- c("CH4" = "#7F28D5",
"CO2" = "#FFBF44")
#...............................................................................
# .
# Sector Plot .
# .
#...............................................................................
#......................... Wrangle ..........................
# Find total emissions for each sector for each gas
plumeDF_sector_tot_emission <- plumes %>%
group_by(ipcc_sector, gas) %>%
summarise(total_emissions = sum(emission_auto, na.rm = TRUE), # Total Emissions
.groups = "drop") %>%
st_drop_geometry() %>%
filter(!ipcc_sector == "") # remove data points with no sector listed
# Turn sectors into factors
# plumeDF_sector_tot_emission$ipcc_sector <- factor(plumeDF_sector_tot_emission$ipcc_sector,
# levels = sector_order)
# ------------ CH4 plot ------------
# Methane Sector plot
plumeDF_CH4_sector_plot <- plumeDF_sector_tot_emission %>%
filter(gas == "CH4") %>%
ggplot() +
#geom_treemap(aes(area = total_emissions, fill = ipcc_sector)) + # tree map
geom_bar(aes(x = "", y = total_emissions, fill = ipcc_sector),
stat="identity",
width = 0.7,
color = "black") +
#coord_polar("y", start=0) + # This makes it a pie plot
#scale_fill_manual(values = sector_color_pal) +
theme_void() +
labs(title = "Methane Plumes",
fill = "Sector") +
theme(plot.title = element_text(size = 13))
# ------------ CO2 plot ------------
# CO2 Sector plot
plumeDF_CO2_sector_plot <- plumeDF_sector_tot_emission %>%
filter(gas == "CO2") %>%
ggplot() +
#geom_treemap(aes(area = total_emissions, fill = ipcc_sector)) + # tree map
geom_bar(aes(x = "", y = total_emissions, fill = ipcc_sector), # Pie chart
stat="identity",
width = 0.7,
color = "black") +
#coord_polar("y", start=0) +
#scale_fill_manual(values = sector_color_pal) +
theme_void() +
labs(title = "Carbon Dioxide Plumes",
fill = "Sector") +
theme(plot.title = element_text(size = 13),
legend.position = "none")
# Plots together
plume_sector_plot <- (plumeDF_CO2_sector_plot | plumeDF_CH4_sector_plot) +
plot_annotation(title = "Sector Composition",
subtitle = "The oil and natural gas sector emits the most methane,\nwhereas Electricity Generation emits the most carbon dioxide.",
caption = "Data Source: Carbon Mapper",
theme = theme(plot.title = element_text(size = 17, face = "bold"),
plot.subtitle = element_text(size = 12, color = "gray60"),
plot.caption = element_text(face = "italic")))
# ggsave(filename = here::here("final_figs", "sector.pdf"),
# plot = plume_sector_plot,
# height = 7,
# width = 9
# )
#...............................................................................
# .
# Background CH4 and CO2 abundance and gwp plots
# .
#...............................................................................
#Bar plot of CO2 and CH4 emission concentrations
gas_total_emissions <- plumes %>%
group_by(gas) %>%
summarise(emission_auto = sum(emission_auto, na.rm = TRUE)) %>%
st_drop_geometry() %>%
ggplot() +
geom_col(aes(x = gas, y = emission_auto, fill = gas)) +
scale_fill_manual(values = gas_pal) +
theme_minimal() +
labs(y = "Total Emission (kg/hr)")
# ggsave(filename = here::here("final_figs", "gas_total_emissions.pdf"),
# plot = gas_total_emissions,
# width = 5,
# height = 5)
# Create dataframe for gwp
gwp <- data.frame(gas = c("CO2", "CH4"),
life_time = c(500, 12.4), # Chem life times
gwp = c(1,28)) # global warmining potential
# Circle Area plots of gwp
gas_gwp_plot <- ggplot() +
geom_point(data = gwp,
mapping = aes(x = gas, y = 0, size = gwp, fill = gas),
shape = 21, color = "black", alpha = 0.7) +
scale_size_area(max_size = 20) + # Ensures area ~ value
coord_fixed(ratio = 5) + # Keep circles round
theme_minimal() +
scale_fill_manual(values = gas_pal, guide = "none") +
labs(
title = "Global Warming Potiential (gwp)",
size = "Value"
) +
theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.y = element_blank(),
axis.title.x = element_blank(),
legend.position = "bottom")
# ggsave(filename = here::here("figs", "gas_gwp_plot.pdf"),
# plot = gas_gwp_plot,
# width = 7,
# height = 5)
#gas_gwp_plot / gas_total_emissions # put plots together
#...............................................................................
# .
# Stream Plot .
# .
#...............................................................................
#......................Wrangle data ..........................
# Find each country's emissions per capita & per million people OVERTIME
plumes_per_country_overtime <-plumes_country %>%
st_drop_geometry() %>%
group_by(name_long, year = year(datetime), month = month(datetime), gas) %>% # Find avg and sum for each month of each year
summarise(total_emissions = sum(emission_auto, na.rm = TRUE),
avg_emissions = mean(emission_auto, na.rm = TRUE),
pop = mean(pop),
.groups = "drop") %>%
mutate(year_dec = year + (month - 1) / 12, #decimal year
emission_total_capita = (total_emissions/pop),
emission_per_million = (total_emissions/pop) * 1e6) # per 1 million people
# Find each country's emissions per capita & per million people in general
plumes_per_country <-plumes_country %>%
st_drop_geometry() %>%
group_by(name_long, gas) %>% # Find total emissions per country
summarise(total_emissions = sum(emission_auto, na.rm = TRUE),
avg_emissions = mean(emission_auto, na.rm = TRUE),
pop = mean(pop),
.groups = "drop") %>%
mutate(emission_total_capita = (total_emissions/pop),
emission_per_million = (total_emissions/pop) * 1e6)
#.....................Find top 10 emitters ........................\
top_countries_CH4 <- plumes_per_country %>%
filter(gas == "CH4") %>%
group_by(name_long) %>%
summarise(total = sum(emission_per_million)) %>%
slice_max(total, n = 10) %>%
pull(name_long)
top_countries_CO2 <- plumes_per_country %>%
filter(gas == "CO2") %>%
group_by(name_long) %>%
summarise(total = sum(emission_per_million)) %>%
slice_max(total, n = 10) %>%
pull(name_long)
#.....................Find top 10 emitters ........................\
# ------------ CH4 plot ------------
# For CH4
plumes_CO2_per_country <- plumes_per_country_overtime %>%
filter(gas == "CH4",
year >= 2023,
name_long %in% top_countries_CH4) %>% # plot just the top 10 CH4 emitters
ggplot(aes(x = year_dec, # use decimal year
y = emission_per_million,
fill = name_long)) +
geom_stream(type = "ridge", bw = 0.85) +
geom_stream_label(aes(label = name_long),
type = "ridge",
size = 2.5) +
theme_minimal() +
theme(axis.title.y = element_blank(),
axis.title.x = element_blank())
# ------------ CO2 plot ------------
# For CO2
plumes_CH4_per_country <- plumes_per_country_overtime %>%
filter(gas == "CO2",
year >= 2023,
name_long %in% top_countries_CO2) %>% # plot just the top 10 CO2 emitters
ggplot(aes(x = year_dec, # use decimal year
y = emission_per_million,
fill = name_long)) +
geom_stream(type = "ridge", bw = 0.85) +
geom_stream_label(aes(label = name_long),
type = "ridge",
size = 2.5) +
theme_minimal() +
theme(axis.title.y = element_blank(),
axis.title.x = element_blank())
# ggsave(filename = here::here("final_figs", "plumes_CO2_per_country.pdf"),
# plot = plumes_CO2_per_country,
# width = 6,
# height = 4)
#
#
# ggsave(filename = here::here("final_figs", "plumes_CH4_per_country.pdf"),
# plot = plumes_CH4_per_country,
# width = 6,
# height = 4)