Introduction

Climate change and rising energy consumption continue to shape global environmental and economic policies. Carbon dioxide (CO2) emissions from fossil fuel use are among the leading contributors to global warming. Understanding how national energy consumption patterns relate to carbon emissions is essential for evaluating sustainability and climate policy effectiveness.

This project explores global carbon footprints and energy consumption trends using the Our World in Data (OWID) CO2 dataset from 2000–2024.

Objectives

The main objectives of this analysis are:

  • Identify the countries with the highest carbon emissions
  • Compare long-term energy consumption trends
  • Examine the relationship between GDP and CO2 emissions
  • Analyze fossil fuel contributions to emissions
  • Explore global greenhouse gas trends

Load Required Libraries

library(tidyverse)
library(plotly)
library(ggthemes)
library(viridis)
library(scales)

Data Source

The dataset used in this project comes from Our World in Data (OWID).

Source: https://github.com/owid/co2-data

Load Dataset

url <- "https://raw.githubusercontent.com/owid/co2-data/master/owid-co2-data.csv"

data <- read_csv(url)
## Rows: 50411 Columns: 79
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (2): country, iso_code
## dbl (77): year, population, gdp, cement_co2, cement_co2_per_capita, co2, co2...
## 
## ℹ 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.

Data Cleaning

clean_data <- data %>%
  filter(year >= 2000) %>%
  filter(!is.na(country)) %>%
  filter(iso_code != "") %>%
  filter(!is.na(co2))

Visualization 1: Top 10 CO2 Emitting Countries

latest_year <- max(clean_data$year, na.rm = TRUE)

top10 <- clean_data %>%
  filter(year == latest_year) %>%
  arrange(desc(co2)) %>%
  slice(1:10)

ggplot(top10,
       aes(x = reorder(country, co2),
           y = co2,
           fill = co2)) +
  geom_col() +
  coord_flip() +
  scale_fill_viridis_c() +
  labs(
    title = "Top 10 CO2 Emitting Countries",
    subtitle = paste("Year:", latest_year),
    x = "Country",
    y = "CO2 Emissions (million tonnes)",
    caption = "Source: Our World in Data"
  ) +
  theme_minimal(base_size = 13)

Interpretation

The chart demonstrates that a relatively small number of countries contribute disproportionately to global carbon emissions. China and the United States remain the largest emitters, reflecting their industrial scale and energy demand.


Visualization 3: Energy Use vs CO2 Emissions

scatter_data <- clean_data %>%
  filter(year == latest_year)

ggplot(scatter_data,
       aes(x = energy_per_capita,
           y = co2_per_capita)) +
  geom_point(alpha = 0.6,
             color = "blue") +
  geom_smooth(method = "lm",
              se = FALSE,
              color = "red") +
  labs(
    title = "Energy Consumption vs CO2 Emissions",
    subtitle = "Relationship Between Energy Use and Carbon Emissions",
    x = "Energy Per Capita",
    y = "CO2 Per Capita (tonnes per person)",
    caption = "Source: Our World in Data"
  ) +
  theme_minimal(base_size = 13)
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 136 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 136 rows containing missing values or values outside the scale range
## (`geom_point()`).

Interpretation

The scatter plot reveals a generally positive relationship between energy consumption and carbon emissions. Countries with higher energy use per person tend to exhibit higher carbon footprints, highlighting the environmental impact of intensive energy consumption.


Visualization 5: Fossil Fuel Contributions

fuel_data <- clean_data %>%
  filter(year == latest_year) %>%
  select(country, coal_co2, oil_co2, gas_co2) %>%
  mutate(
    total = coal_co2 + oil_co2 + gas_co2
  ) %>%
  arrange(desc(total)) %>%
  slice(1:10)

fuel_long <- fuel_data %>%
  pivot_longer(cols = c(coal_co2, oil_co2, gas_co2),
               names_to = "fuel",
               values_to = "emissions")

ggplot(fuel_long,
       aes(x = reorder(country, total),
           y = emissions,
           fill = fuel)) +
  geom_bar(stat = "identity") +
  coord_flip() +
  labs(
    title = "Fossil Fuel Contributions to CO2 Emissions",
    subtitle = "Coal, Oil, and Gas Emissions by Country",
    x = "Country",
    y = "CO2 Emissions",
    fill = "Fuel Type",
    caption = "Source: Our World in Data"
  ) +
  theme_minimal(base_size = 13)

Interpretation

Different countries rely on different fossil fuel sources for energy production. Coal remains a dominant contributor in several rapidly industrializing economies, while oil and gas contribute more prominently in others.


Visualization 6: Interactive GDP vs CO2 Emissions Per Capita

gdp_data <- clean_data %>%
  filter(year == 2022) %>%
  filter(
    !is.na(gdp),
    !is.na(co2_per_capita),
    gdp > 0,
    co2_per_capita > 0
  )

plot_ly(
  data = gdp_data,
  x = ~gdp / 1000000000000,
  y = ~co2_per_capita,
  type = "scatter",
  mode = "markers",
  text = ~country,
  hovertemplate =
    paste(
      "<b>%{text}</b><br>",
      "GDP: %{x:.2f} Trillion USD<br>",
      "CO2 Per Capita: %{y:.2f} tonnes/person",
      "<extra></extra>"
    ),
  marker = list(
    size = 10,
    color = "darkgreen",
    opacity = 0.6
  )
) %>%
  layout(
    title = "Interactive GDP vs CO2 Emissions Per Capita (2022)",
    xaxis = list(title = "GDP (Trillion USD)"),
    yaxis = list(title = "CO2 Emissions Per Capita (tonnes/person)")
  )

Interpretation

The interactive bubble chart demonstrates a positive association between economic development and carbon emissions per person. However, several countries achieve relatively high GDP levels with moderate emissions, suggesting improved efficiency and cleaner energy adoption.


Visualization 7: Distribution of CO2 Emissions Per Capita

ggplot(scatter_data,
       aes(x = co2_per_capita)) +
  geom_histogram(fill = "skyblue",
                 color = "black",
                 bins = 30) +
  labs(
    title = "Distribution of CO2 Emissions Per Capita",
    subtitle = "Global Distribution Across Countries",
    x = "CO2 Emissions Per Capita (tonnes/person)",
    y = "Frequency",
    caption = "Source: Our World in Data"
  ) +
  theme_minimal(base_size = 13)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

Interpretation

Most countries exhibit relatively low per-capita emissions, while a smaller number demonstrate extremely high values. This indicates considerable inequality in global carbon footprints.


Visualization 8: Interactive Top 10 CO2 Emitters

plot_ly(
  data = top10,
  x = ~country,
  y = ~co2,
  type = "bar",
  color = ~co2
) %>%
  layout(
    title = "Interactive Top 10 CO2 Emitting Countries",
    xaxis = list(title = "Country"),
    yaxis = list(title = "CO2 Emissions")
  )
## Warning: textfont.color doesn't (yet) support data arrays
## Warning: textfont.color doesn't (yet) support data arrays

Interpretation

The interactive visualization enables users to dynamically compare emission levels among the world’s highest-emitting countries and observe the substantial differences in national carbon outputs.


Conclusion

This project explored global carbon emissions and energy consumption patterns between 2000 and 2024 using the OWID dataset.

Key findings include:

The findings highlight the importance of sustainable energy transitions and environmentally responsible economic development in reducing future greenhouse gas emissions.

References