Load the necessary packages and set plotting default

rm(list = ls())

## First specify the packages of interest
packages = c("tidyverse", "dplyr","ggplot2","plotly","viridis","wbstats","gtrendsR","ggforce","spData","tmap","gganimate","urltools")

## Now load or install&load all
package.check <- lapply(
  packages,
  FUN = function(x) {
    if (!require(x, character.only = TRUE)) {
      install.packages(x, dependencies = TRUE)
      library(x, character.only = TRUE)
    }
  }
)


def_plot_set <- par(mfrow =c(1,1),mar=c(1, 1, 1, 1))
on.exit(par(def_plot_set))

Part 1: Use world bank data for analysis - Analyse \(CO_2\) emission over the years

A. Load required data from wbstats package

wc = wb_countries()
wd = wb_data(indicator = c("SP.POP.TOTL","EN.ATM.CO2E.PC","NY.GDP.PCAP.CD"), 
   country = "countries_only", start_date = 1970, end_date = 2018,date_as_class_date = TRUE)

df <- left_join(wd,wc,by = c("iso2c", "iso3c", "country")) 
df <- df[,c(3:15)]
df <- na.omit(df)

B. Analysis

\(CO_2\) emissions has been a matter of concern for quite sometime. More \(CO_2\) in the atmosphere means more heat from the sun is trapped inside our atmosphere- increasing the global temperature. The pre-industrial concentration of \(CO_2\) was 280 parts per million which increased to 409 ppm when measured in 2018. And it is anticipated to reach approximately 600 ppm in next 30 years if the emission continued at this pace. The graph below shows this upward spiral of World’s \(CO_2\) levels.

ind <- "EN.ATM.CO2E.PC"
indicator_info <- filter(wb_cachelist$indicators, indicator_id == ind)
df %>% dplyr::mutate(Year=date) %>%
  group_by(Year) %>%
  summarise(Emissions = sum(`EN.ATM.CO2E.PC`)) %>%
  ggplot(aes(x=Year,y= Emissions)) +
  labs(title = "World's " ~CO[2]~ "emissions over the years",
       caption = paste("Source:", indicator_info$source_org),
       x = "Year",
       y = ~CO[2]~ "Emissions (metric tons per capita)",
       col = "Continents") +
  theme_classic() +
  geom_line(size=1.5,col="red")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Now, that we saw Global \(CO_2\) level. Let`s see continent-wise \(CO_2\) emissions over years.

wc = wb_countries()
wd = wb_data(indicator = c("SP.POP.TOTL","EN.ATM.CO2E.PC","NY.GDP.PCAP.CD"), 
   country = "countries_only", start_date = 1970, end_date = 2018,date_as_class_date = TRUE)

df <- left_join(wd,wc,by = c("iso2c", "iso3c", "country")) 
df <- df[,c(3:15)]
df <- na.omit(df)

df2 <- df %>% dplyr::mutate(Year=date) %>%
  group_by(Year,region) %>%
  summarise(Emissions = sum(`EN.ATM.CO2E.PC`))
  ggplot(df2,aes(x=Year,y= Emissions,col=region)) + geom_line(size=1) +
    labs(title = "World's " ~CO[2]~ "emissions over the years: Continent-wise",
       caption = paste("Source:", indicator_info$source_org),
       x = "Year",
       y = ~CO[2]~ "Emissions (metric tons per capita)",
       col = "Continents") +
    theme_classic()

WOW! Some contributed much more than others in the global \(CO_2\) emissions. It becomes important to analyze if this was primarily due to population growth in these continent or if this is due to carbon intensive lifestyle.

wc = wb_countries()
wd = wb_data(indicator = c("SP.POP.TOTL","EN.ATM.CO2E.PC","NY.GDP.PCAP.CD"), 
   country = "countries_only", start_date = 1970, end_date = 2018,date_as_class_date = TRUE)

df <- left_join(wd,wc,by = c("iso2c", "iso3c", "country")) 
df <- df[,c(3:15)]
df <- na.omit(df)

df2 <- df %>% dplyr::mutate(Year=date) %>%
  group_by(Year,region) %>%
  summarise(Population = sum(`SP.POP.TOTL`))
  ggplot(df2,aes(x=Year, y= Population, col=region)) + geom_line(size=1) +
    labs(title = "Population increase over the years- cut by Continent",
       caption = "Source: World Bank | @wbstats",
       x = "Year",
       y = "Population",
       col = "Continents") +
  theme_classic()

Yes, Population growth is one of the many reason because more population means more demand for fossil fuels which means more emission. Interestingly, the continent with highest emissions are the one with second lowest population which means this continent uses the most carbon intensive lifestyle.

To sum it up- the graph below shows the relationship between \(CO_2\) emissions(per capita), GDP(per capita) and population growth over the years.

wc = wb_countries()
wd = wb_data(indicator = c("SP.POP.TOTL","EN.ATM.CO2E.PC","NY.GDP.PCAP.CD"), 
   country = "countries_only", start_date = 1970, end_date = 2018)

df <- left_join(wd,wc,by = c("iso2c", "iso3c", "country")) 
df <- df[,c(3:15,18)]
df <- na.omit(df)
df$Year = df$date
df$date <- as.factor(df$date)

ggplot(df, aes(x = log(`NY.GDP.PCAP.CD`), y =`EN.ATM.CO2E.PC`, size = `SP.POP.TOTL`)) +
  geom_point(alpha = 0.5, aes(color = region)) +
  scale_size(range = c(.1, 16), guide = "none") +
  scale_colour_brewer(palette = "Dark2") +
  scale_x_continuous(limits = c(2.5, 11)) +
  scale_y_continuous(limits = c(0, 18)) +
    labs(title = "Relationship between CO2 emissions and income, over the years",
       caption = "Source: World Bank | @wbstats",
       x = "GDP per capita ($)",
       y = "CO2 emissions (metric tons per capita)",
       col = "Continents") +
     theme_classic() +
    theme(plot.title = element_text(size = 14),
          axis.title = element_text(size = 10),
          axis.text = element_text(size = 10),
          legend.text=element_text(size=8))+
    geom_text(aes(x = 5, y = 10, label = date), size = 12, color = 'lightgrey', family = 'Oswald') +
    transition_states(date, transition_length = 25, state_length = 25)+ ease_aes('cubic-in-out')

The world’s wealthiest 10% were responsible for around half of global emissions in 2015, according to a 2020 from Oxfam and the Stockholm Environment Institute. Over the years, other not-so-rich countries too joined the race. Many of the world`s ecosystem is at its limit and if the consumption pattern is not checked then we will be responsible for this mass damage - ecocide