Load Libraries

library(readr)
library(tidyr)
library(ggplot2)
library(plotly)

Load Data Set

I have found an interesting map figure from the “Our World in Data” site. The code to load the datset is below:

gw_potential <- readr::read_csv("https://ourworldindata.org/grapher/global-warming-potential-of-greenhouse-gases-over-100-year-timescale-gwp.csv?v=1&csvType=filtered&useColumnShortNames=true")
print(gw_potential)
## # A tibble: 6 × 5
##   Entity                     Code   Year gwp_100  time
##   <chr>                      <lgl> <dbl>   <dbl> <dbl>
## 1 Carbon dioxide (CO₂)       NA     2021     1    2021
## 2 HFC-152a (CH₃CHF₂)         NA     2021   164    2021
## 3 Methane (CH₄)              NA     2021    27.9  2021
## 4 Nitrous oxide (N₂O)        NA     2021   273    2021
## 5 PFC-14 (CF₄)               NA     2021  7380    2021
## 6 Sulphur hexafluoride (SF₆) NA     2021 24300    2021

Create Original Plot

# create plot

ggplot(gw_potential, aes(x = gwp_100, y = reorder(Entity, gwp_100))) +
  geom_bar(stat = "identity", fill = "#6082A6") +
  geom_text(aes(label = gwp_100), 
            hjust = -0.1, 
            size = 3.5,     
            color = "#636363") +
  labs(
    title = "Global warming potential of greenhouse gases relative to CO₂",
    subtitle = "Global warming potential measures the relative warming impact of one unit mass of a\ngreenhouse gas relative tocarbon dioxide over a 100-year timescale",
    x = "",
    y = ""
  ) +
  theme_minimal() +
  theme(
    panel.grid = element_blank(),
    axis.text.x = element_blank(),
    axis.line.y = element_line(color = "grey", linewidth = 0.2),
    axis.ticks.length = unit(0.2, "cm"),
    plot.title = element_text(
      family = "Times New Roman",
      size = 20,
      color = "#636363"
    ),
  plot.margin = margin(10, 75, 10, 10)
  ) +
  scale_x_continuous(expand = c(0, 0), limits = c(0, NA)) +
  coord_cartesian(xlim = c(0, max(gw_potential$gwp_100) * 1.1))

Improve the original plot

# improve plot

gw_potential$Entity <- reorder(gw_potential$Entity, -gw_potential$gwp_100)

ggplot(gw_potential, aes(x = gwp_100, y = reorder(Entity, -gwp_100), fill = Entity)) +
  geom_bar(stat = "identity") +
  geom_text(aes(label = gwp_100), 
            hjust = -0.1, 
            size = 3.5,     
            color = "#636363") +
  labs(
   title = "Global warming potential of greenhouse gases",
    subtitle = "Global warming potential (GWP) measures the relative warming impact of one\nunit mass of a greenhouse gas relative tocarbon dioxide over a 100-year timescale",
    x = "GWP",
    y = "Greenhouse Gas"
  ) +
  theme_minimal() +
  theme(
    panel.grid = element_blank(),
    axis.text.x = element_blank(),
    axis.ticks.length = unit(0.2, "cm"),
    plot.title = element_text(
      family = "Times New Roman",
      size = 20,
      color = "#636363"
    ),
  plot.margin = margin(10, 75, 10, 10),
  legend.position = c(0.7, 0.6), 
    legend.background = element_rect(fill = "white", color = "grey", size = 0.5), 
    legend.key.size = unit(0.6, "cm") 
  ) +
  scale_x_continuous(expand = c(0, 0), limits = c(0, NA)) +
  coord_cartesian(xlim = c(0, max(gw_potential$gwp_100) * 1.1)) +
  scale_fill_brewer(palette = "RdYlGn")

Interactive plot

gw_potential$full_name <- c("Carbon dioxide", "HFC-152a", "Methane",
                            "Nitrous oxide", "PFC-14", "Sulfur hexafluoride")

gw_potential$abb_name <- c("CO2", "CH3CHF", "CH4", "N2O", "CF4", "SF6")

gw_potential$top_sources <- c("Electricity (31%), Agriculture (11%), Transportation (15%), Manufacturing (12%)", "Refrigeration (79%), Foams (11%), Aerosols (5%), Other (5%)", "Agriculture (40%), Fossil fuel (35%), Waste (20%)", "Agriculture (75%), Stationary combustion (6%), Wastewater treatment (6%)", "Referigeration (58%), Fire protection (20%), Solvents (9%)", "Electricity and heat (67%), Metal smelting (20%)")

gw_potential$full_name <- reorder(gw_potential$full_name, -gw_potential$gwp_100)

plot <- ggplot(gw_potential, aes(x = gwp_100, y = reorder(full_name, -gwp_100), fill = full_name, text = paste("<br>Chemical Formula: ", abb_name, "<br>GWP: ", gwp_100, "<br>Top Emission Sources: ", top_sources))) +
  geom_bar(stat = "identity") +
  labs(
    title = "Global warming potential of greenhouse gases",
    subtitle = "Global warming potential (GWP) measures the relative warming impact of one\nunit mass of a greenhouse gas relative to carbon dioxide over a 100-year timescale",
    x = "GWP",
    y = "Greenhouse Gas"
  ) +
  theme_minimal() +
  theme(
    panel.grid = element_blank(),
    axis.text.x = element_blank(),
    axis.ticks.length = unit(0.2, "cm"),
    plot.title = element_text(
      family = "Times New Roman",
      size = 20,
      color = "#636363"
    ),
    plot.margin = margin(10, 75, 10, 10),
    legend.position = c(0.7, 0.6), 
    legend.background = element_rect(fill = "white", color = "grey", size = 0.5), 
    legend.key.size = unit(0.6, "cm") 
  ) +
  scale_x_continuous(expand = c(0, 0), limits = c(0, NA)) +
  coord_cartesian(xlim = c(0, max(gw_potential$gwp_100) * 1.1)) +
  scale_fill_brewer(palette = "RdYlGn", direction = 1)

interactive_plot <- ggplotly(plot, tooltip = "text") %>%
  layout(
    showlegend = TRUE,
    legend = list(
      title = list(text = 'Greenhouse Gas'),
      traceorder = 'normal'
    )
  )

interactive_plot