CO2-Global-Emissions-Analysis

Global CO₂ Emissions Analysis

A comprehensive R-based analysis that fetches and processes global CO₂ emissions data (per-capita and total) from Our World in Data (OWID), generates a suite of 12 exploratory and analytical plots, and performs a regression of per-capita emissions on GDP per capita.

Table of Contents

  1. Project Overview
  2. Features & Charts
  3. Prerequisites
  4. Installation
  5. Usage
  6. Script Breakdown
  7. Interpreting the Outputs
  8. Extending & Customizing
  9. Data Source & Citations
  10. License

Project Overview

This repository contains:


Features & Charts

  1. Global Trend
    • Line plot of global average CO₂ per capita over time
  2. GDP vs. CO₂
    • Scatter of GDP per capita vs. CO₂ per capita (latest) with LOESS smoothing
  3. Regression Analysis
    • Linear model summary printed to console
    • Scatter + regression line with R² and p-value annotation
  4. Top 10 Emitters (per capita)
    • Horizontal bar chart of the 10 highest per-capita emitters
  5. Top 5 Time Series
    • Line plots of CO₂ per capita over time for the top 5 countries
  6. Quartile Boxplot
    • CO₂ per capita by GDP per capita quartile (boxplot)
  7. Quartile Violin
    • Distribution of CO₂ per capita by GDP quartile (violin plot)
  8. Quartile Heatmap
    • Heatmap of average CO₂ per capita by year & GDP quartile
  9. Cumulative Sum
    • Cumulative sum of per-capita CO₂ over time
  10. Year-over-Year Change
    • Line plot of YOY % change in global average CO₂ per capita
  11. Total vs. Per Capita
    • Scatter of total CO₂ emissions vs. per-capita emissions (log scale)
  12. Global Time Series
    • (Already #1) — the core global trend


Prerequisites

R Packages

The main script auto-installs any missing packages.


Installation

  1. Clone this repository:

    git clone https://github.com/yourusername/co2-analysis.git
    cd co2-analysis
    
  2. Optional: copy .env.example.env to set DATA_DIR if you prefer a custom data folder.


Usage

From R or RStudio

# Set working directory to the project root
setwd("path/to/co2-analysis")

# Source the analysis script
source("CO2_Analysis.R")

All charts will render in sequence and the regression summary will print to the console.

Via Make

make report

This will:

  1. Fetch the CO₂ CSV into data/
  2. Run CO2_Analysis.R
  3. Render CO2_Analysis.RmdCO2_report.html

Via Docker

docker-compose up --build

This runs the entire pipeline in a reproducible container.


Script Breakdown

  1. Setup

    • Defines package list, auto-installs, and loads libraries.
  2. Data Fetch & Prep

    • Downloads OWID CSV, filters to years ≥1960, computes co2_pc, total_co2, gdp_pc.
    • Derives date from year.
  3. Visualization Sections

    • Global trend, GDP relationship, top emitter charts, quartile analyses, cumulative sums, YOY change, total vs. per-capita.
  4. Regression

    • Fits lm(co2_pc ~ gdp_pc), prints summary(), and generates an annotated plot.

Interpreting the Outputs


Extending & Customizing


Data Source & Citations


License

This project is released under the MIT License. See LICENSE for details.