Task 1: Use world bank data to analyze CO2 emissions

I use the wbstats package to first obtain data on global CO2 emissions per capita in metric tons. I extract the data using world bank API and map the emissions per capita for different countries.

The map below shows that per capita emissions is highest in USA, Canada, Australia and Saudi Arabia, while the emissions are lowest in Sub-Saharan Africa, the Indian subcontinent and South America.

library(wbstats)
library(rnaturalearth)
library(rnaturalearthdata)
library(ggplot2)
library(viridis)
library(dplyr)
library(sf)

# Get data from indicators
world_map <- rnaturalearth::ne_countries(scale = 50, returnclass = "sf")
co2emission <- wb(country = "countries_only",
                  indicator = "EN.ATM.CO2E.PC",
                  mrv = 1)
co2_pc <- left_join(world_map, co2emission, by = c("iso_a2" = "iso2c"))

# Plot world map of CO2 emissions per capita

g <- ggplot(co2_pc) +
  geom_sf(aes(fill = value)) +
  scale_fill_viridis("value") +
  ggtitle("CO2 emissions (metric tons per capita)") +
  theme_bw()
g

To get a complete picture, I also extract data on total CO2 emissions (in kt) for each country. This is shown in the map below. The highest CO2 emissions are from China followed by USA followed by India.

co2_tot <- wb(country = "countries_only",
                  indicator = "EN.ATM.CO2E.KT",
              mrv = 1)
co2_kt <- left_join(world_map, co2_tot, by = c("iso_a2" = "iso2c"))

g2 <- ggplot(co2_kt) +
  geom_sf(aes(fill = value)) +
  scale_fill_viridis("value") +
  ggtitle("CO2 emissions (kt)") +
  theme_bw()
g2