library(gtrendsR)
## Warning: package 'gtrendsR' was built under R version 4.1.3
## Warning in register(): Can't find generic `scale_type` in package ggplot2 to
## register S3 method.
library(reshape2)
## Warning: package 'reshape2' was built under R version 4.1.3
library(ggplot2)
library(maps)
## Warning: package 'maps' was built under R version 4.1.3
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(wbstats)
## Warning: package 'wbstats' was built under R version 4.1.3
library(sf)
## Warning: package 'sf' was built under R version 4.1.3
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
library(viridis)
## Warning: package 'viridis' was built under R version 4.1.3
## Loading required package: viridisLite
## 
## Attaching package: 'viridis'
## The following object is masked from 'package:maps':
## 
##     unemp
library(rnaturalearth)
## Warning: package 'rnaturalearth' was built under R version 4.1.3
library(rnaturalearthdata)
## Warning: package 'rnaturalearthdata' was built under R version 4.1.3

Task 1: Use world bank data to analyze something

In this section, I have used the per-capita CO2 emissions in the year 2018 (pre COVID-19) around the world from world bank. First, I have extracted the data from world bank API for per capita emissions for all countries and then represented graphically using the world map.

worldmap_data <- rnaturalearth::ne_countries(scale = 50, returnclass = "sf") 
 
 
emi_data <- wb_data(country = "countries_only", 
                     indicator = "EN.ATM.CO2E.PC", 
                     mrv = 1)
 
emi_world <- left_join(worldmap_data, emi_data, by = c("iso_a2" = "iso2c"))

Per Capita CO2 Emission around the World during pre covid-19 era

North American countries have the highest amount of per-capita CO2 emissions followed by Australia and Middle Eastern countries. Moreover, African and South American countries have comparatively less per-capita CO2 emissions.

ggplot(emi_world) +
  geom_sf(aes(fill = EN.ATM.CO2E.PC)) +
  scale_fill_viridis("value") +
  ggtitle(" CO2 emissions (metric tons per capita for 2018)") +
  theme_bw()

Trajectory of CO2 emissions within the last two decades among the largest emitter countries

I have also tried to see the trajectory of some of the highest CO2 emitter countries US EPA (2018). The red vertical line is the date for COP21 (Paris Agreement). The threshold has been used to see whether those countries were able to lower their emission level after the COP21. From the following graph, we can see that China is largest CO2 emitter country around the world with a growing tend over the years. United states is the second largest emitter with a somewhat constant trend of emissions. Apart from India, all the other countries exhibiting a constant level of carbon emissions over the years.

emi7C <- wb(country = c("US", "CA", "IN", "JPN", "DEU", "CHN", "RUS"), indicator = "EN.ATM.CO2E.KT", startdate = 1998, enddate = 2018)
## Warning: `wb()` was deprecated in wbstats 1.0.0.
## Please use `wb_data()` instead.
emi7C1 <- mutate(emi7C, emission = value/1000)

 
ggplot(emi7C1, aes(x=as.numeric(date), y=emission, color= country)) + 
  geom_line() + ggtitle("Trajectory of CO2 Emission from 1998 to 2018")+
  theme(plot.title = element_text(size = 11, face = "bold")) +
  ylab("CO2 emissions (Mega t)") + xlab("Year") +
  theme(axis.title = element_text(size = 8))+ theme_classic()+
  geom_vline(xintercept = 2015, color = "red",size = 0.5)

World Bank have CO2 emissions data for only until 2018. It would have been interesting to see how the emissions level changed due to the pandemic (especially due to reduced air traffic) for both the above graphs.