Skip to content

Climate Change and its Impacts in Africa

According to the United Nations, Climate change refers to long-term shifts in temperatures and weather patterns. Such shifts can be natural, due to changes in the sun’s activity or large volcanic eruptions. But since the 1800s, human activities have been the main driver of climate change, primarily due to the burning of fossil fuels like coal, oil, and gas.

The consequences of climate change now include, among others, intense droughts, water scarcity, severe fires, rising sea levels, flooding, melting polar ice, catastrophic storms, and declining biodiversity.

You work for a Non-governmental organization tasked with reporting the state of climate change in Africa at the upcoming African Union Summit. The head of analytics has provided you with IEA-EDGAR CO2 dataset which you will clean, combine and analyze to create a report on the state of climate change in Africa. You will also provide insights on the impact of climate change on African regions (with four countries, one from each African region, as case studies).

Dataset

The dataset, IEA-EDGAR CO2, is a component of the EDGAR (Emissions Database for Global Atmospheric Research) Community GHG database version 7.0 (2022) including or based on data from IEA (2021) Greenhouse Gas Emissions from Energy, www.iea.org/statistics, as modified by the Joint Research Centre. The data source was the EDGARv7.0_GHG website provided by Crippa et. al. (2022) and with DOI.

The dataset contains three sheets - IPCC 2006, 1PCC 1996, and TOTALS BY COUNTRY on the amount of CO2 (a greenhouse gas) generated by countries between 1970 and 2021. You can download the dataset from your workspace or inspect the dataset directly here.

TOTALS BY COUNTRY SHEET

This sheet contains the annual CO2 (kt) produced between 1970 - 2021 in each country. The relevant columns in this sheet are:

ColumnsDescription
C_group_IM24_shThe region of the world
Country_code_A3The country code
NameThe name of the country
Y_1970 - Y_2021The amount of CO2 (kt) from 1970 - 2021

IPCC 2006

These sheets contain the amount of CO2 by country and the industry responsible.

ColumnsDescription
C_group_IM24_shThe region of the world
Country_code_A3The country code
NameThe name of the country
Y_1970 - Y_2021The amount of CO2 (kt) from 1970 - 2021
ipcc_code_2006_for_standard_report_nameThe industry responsible for generating CO2

1 hidden cell
# Setup
library(dplyr)
library(readxl)
library(readr)
library(tidyr)
library(ggplot2)
library(assertthat)
library(broom)
library(stringr)

# we need only the African regions
african_regions <- c('Eastern_Africa', 'Western_Africa', 'Southern_Africa', 'Northern_Africa')

ipcc_2006_africa <- read_xlsx("IEA_EDGAR_CO2_1970-2021.xlsx", sheet = 'IPCC 2006', skip = 10) %>% 
  filter(C_group_IM24_sh %in% african_regions)

totals_by_country_africa <- read_xlsx("IEA_EDGAR_CO2_1970-2021.xlsx", sheet = 'TOTALS BY COUNTRY', skip = 10) %>% 
  filter(C_group_IM24_sh %in% african_regions)

# Read the temperatures datasets containing four African countries
# One from each African Region:
# Nigeria:    West Africa
# Ethiopa :   East Africa
# Tunisia:    North Africa
# Mozambique: South Africa
temperatures <- read_csv('temperatures.csv')

temperatures data set

temperatures
# DO NOT MODIFY THIS CELL
# load the tests runner
source('tests.R')

1 hidden cell
# CREATING BACK_UP'S
ipcc_2006_africa_BACK_UP = ipcc_2006_africa
totals_by_country_africa_BACK_UP = totals_by_country_africa
# REVERSE BACK_UP (TO BE USED MORE OFTEN)
ipcc_2006_africa = ipcc_2006_africa_BACK_UP
totals_by_country_africa = totals_by_country_africa_BACK_UP
# Your code here

# A PART ###############################################################################

# for the ipcc_2006_africa data set
ipcc_2006_africa = ipcc_2006_africa %>% 
                   rename(Region = C_group_IM24_sh,
	                      Code = Country_code_A3,
	                      Industry = ipcc_code_2006_for_standard_report_name) %>% 
                   select(-1,-5, -7) %>% 
                   gather(key = "Year", value = "CO2", 6:Y_2021) %>% 
                   drop_na()

# From the stringr package
ipcc_2006_africa$Year = str_replace(ipcc_2006_africa$Year, "Y_", " ")

ipcc_2006_africa$Year = as.integer(ipcc_2006_africa$Year)

# OR (1) ############
# ipcc_2006_africa %>% 
#  mutate(Year = as.integer(str_replace(Year, "Y_", " ")))

# OR (2)  ###########
#  ipcc_2006_africa %>% 
#  mutate(Year = as.integer(str_remove(Year, "Y_")))

############################################################################################################
# B PART
# For the totals_by_country_africa data set

totals_by_country_africa =  totals_by_country_africa %>% 
                   rename(Region = C_group_IM24_sh,
	                      Code = Country_code_A3) %>% 
                   select(-1,-5) %>% 
                   gather(key = "Year", value = "CO2", 4:Y_2021) %>% 
                   drop_na()

# From the stringr package
totals_by_country_africa$Year = str_replace(totals_by_country_africa$Year, "Y_", " ")

totals_by_country_africa$Year = as.integer(totals_by_country_africa$Year)

First 6 rows for totals_by_country_africa and ipcc_2006_africa respectively

head(totals_by_country_africa)
head(ipcc_2006_africa)
# DO NOT MODIFY THIS CELL
# Run this cell to determine if you've done the above correctly
# If there are no error messages, you are correct :)
runner$check_task_1(ipcc_2006_africa, totals_by_country_africa)

1 hidden cell
# Your code here
# Summarizing by Region and Year
co2_level_by_region_per_year = totals_by_country_africa %>% 
                               group_by(Region, Year) %>% 
                               summarise(co2_level = mean(CO2))

# Visualizing Data
trend_of_CO2_emission_plot = co2_level_by_region_per_year %>% 
                             ggplot(aes(Year,co2_level)) +
                             geom_line() + 
                             facet_wrap(~Region, scales = "free_y")