Final Project Rough Draft
Author

Calvin Cuff

Published

January 19, 2024

Code
library(dplyr)
library(here)
library(readr)
library(tidyverse)

Import the Dataset

For this project I will be importing the CO2_Emissions_Global_Trade.csv data set which was sourced from the IMF Climate Change Dashboard.

Code
co2_emissions <- read_csv(here("data", "CO2_Emissions_Global_Trade.csv"))
Rows: 402 Columns: 38
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (10): Country, ISO2, ISO3, Indicator, Unit, Source, CTS_Code, CTS_Name, ...
dbl (28): ObjectId, F1995, F1996, F1997, F1998, F1999, F2000, F2001, F2002, ...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Code
head(co2_emissions)
# A tibble: 6 × 38
  ObjectId Country   ISO2  ISO3  Indicator        Unit  Source CTS_Code CTS_Name
     <dbl> <chr>     <chr> <chr> <chr>            <chr> <chr>  <chr>    <chr>   
1        1 Argentina AR    ARG   CO2 Emissions E… Mill… "OECD… ECBTDB   CO2 Emi…
2        2 Argentina AR    ARG   CO2 Emissions E… Mill… "OECD… ECBTDD   CO2 Emi…
3        3 Argentina AR    ARG   CO2 Emissions E… Mill… "OECD… ECBTTX   CO2 Emi…
4        4 Argentina AR    ARG   CO2 Emissions E… Mill… "OECD… ECBTT    CO2 Emi…
5        5 Argentina AR    ARG   CO2 Emissions E… Mill… "OECD… ECBTT    CO2 Emi…
6        6 Argentina AR    ARG   CO2 Emissions E… Mill… "OECD… ECBTP    CO2 Emi…
# ℹ 29 more variables: CTS_Full_Descriptor <chr>, Scale <chr>, F1995 <dbl>,
#   F1996 <dbl>, F1997 <dbl>, F1998 <dbl>, F1999 <dbl>, F2000 <dbl>,
#   F2001 <dbl>, F2002 <dbl>, F2003 <dbl>, F2004 <dbl>, F2005 <dbl>,
#   F2006 <dbl>, F2007 <dbl>, F2008 <dbl>, F2009 <dbl>, F2010 <dbl>,
#   F2011 <dbl>, F2012 <dbl>, F2013 <dbl>, F2014 <dbl>, F2015 <dbl>,
#   F2016 <dbl>, F2017 <dbl>, F2018 <dbl>, F2019 <dbl>, F2020 <dbl>,
#   F2021 <dbl>

Tidy Data

Clean the data as needed using dplyr and related tidyverse packages.

To tidy this data, we are only going to select the important columns containing data. There is a lot of repetition and lengthy descriptions, as well as fields that do not vary across rows of data. We will keep the country name, country code (ISO3), indicator, and columns for the years.

Lengthy descriptions

The years column also has an ‘F’ prefix that should be removed. I also don’t like how the indicator is such a long string, we can mutate this column to be more easily parseable. Using the stringr package we can remove the prefix and replace spaces with underscores. The values for indicator have 5 possible options so that is well suited to be converted to a factor.

Code
co2_emissions_tidy <- co2_emissions %>%
  # Select the relevant columns
  select(Country, ISO3, Indicator, 12:38) %>%
  # Rename columns
  rename(country = Country, country_code = ISO3,indicator = Indicator)

# Remove prefix on year column
names(co2_emissions_tidy) <- sub('^F', '', names(co2_emissions_tidy))

# Mutate the Indicator column to be more easily readable
co2_emissions_tidy <- co2_emissions_tidy %>%
  # Fix up indicator - remove prefix, remove commas, replace ' ' with '_', and lowercase everything
  mutate(indicator = tolower(str_replace_all(str_remove(str_remove(indicator, "Emissions Embodied in "), ","), " ", "_")))

# Turn indicator to factor
co2_emissions_tidy$indicator <- as.factor(co2_emissions_tidy$indicator)

head(co2_emissions_tidy)
# A tibble: 6 × 30
  country   country_code indicator     `1995` `1996` `1997` `1998` `1999` `2000`
  <chr>     <chr>        <fct>          <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>
1 Argentina ARG          co2_final_de… -14.4   -15.6  -17.5  -21.8  -19.3  -18.1
2 Argentina ARG          co2_final_do… 124.    136.   141.   152.   151.   148. 
3 Argentina ARG          co2_gross_ex…   9.47   11.4   15.2   13.6   12.5   14.6
4 Argentina ARG          co2_gross_ex… -14.4   -15.6  -17.5  -21.8  -19.3  -18.1
5 Argentina ARG          co2_gross_im…  23.5    26.7   32.3   34.9   31.3   32.4
6 Argentina ARG          co2_producti… 109.    120.   123.   130.   132.   130. 
# ℹ 21 more variables: `2001` <dbl>, `2002` <dbl>, `2003` <dbl>, `2004` <dbl>,
#   `2005` <dbl>, `2006` <dbl>, `2007` <dbl>, `2008` <dbl>, `2009` <dbl>,
#   `2010` <dbl>, `2011` <dbl>, `2012` <dbl>, `2013` <dbl>, `2014` <dbl>,
#   `2015` <dbl>, `2016` <dbl>, `2017` <dbl>, `2018` <dbl>, `2019` <dbl>,
#   `2020` <dbl>, `2021` <dbl>

Now that this data is more friendly, I want to pivot this data longer to collapse the years into rows. We will also sort the data based on year, then country, then customize the order by Indicator for a more intuitive numerical view.

Code
co2_longer <- co2_emissions_tidy %>%
    # Pivot year columns to rows
    pivot_longer(cols = 4:30  , names_to = "year", values_to = "metric_tons_millions") %>% 
    # Sort by year, country, custom Indicator
    arrange(year, country, factor(indicator, levels = c("co2_production", "co2_final_domestic_demand", "co2_final_demand_balance", 
                                                        "co2_gross_exports", "co2_gross_imports", "co2_gross_exports_balance"))) %>%
   # Move year to first column
   select(year, everything())

head(co2_longer)
# A tibble: 6 × 5
  year  country   country_code indicator                 metric_tons_millions
  <chr> <chr>     <chr>        <fct>                                    <dbl>
1 1995  Argentina ARG          co2_production                          109.  
2 1995  Argentina ARG          co2_final_domestic_demand               124.  
3 1995  Argentina ARG          co2_final_demand_balance                -14.4 
4 1995  Argentina ARG          co2_gross_exports                         9.47
5 1995  Argentina ARG          co2_gross_imports                        23.5 
6 1995  Argentina ARG          co2_gross_exports_balance               -14.4 
Code
dim(co2_longer)
[1] 10854     5
Code
colnames(co2_longer)
[1] "year"                 "country"              "country_code"        
[4] "indicator"            "metric_tons_millions"

Describe the Data

This data set contains information about CO2 emissions from domestic demand, production and trade for 66 countries and their ISO3 codes from 1995-2021 measured in millions of metric tons. By tailing the data we can see for 2019-2021 there are only values for the export and import emissions with not all countries having data. There is data for 66 areas, including a lot of prominent countries, as well as ‘Rest of World’.

Code
unique(co2_longer$country)
 [1] "Argentina"                "Australia"               
 [3] "Austria"                  "Belgium"                 
 [5] "Brazil"                   "Brunei Darussalam"       
 [7] "Bulgaria"                 "Cambodia"                
 [9] "Canada"                   "Chile"                   
[11] "China, P.R.: Hong Kong"   "China, P.R.: Mainland"   
[13] "Colombia"                 "Costa Rica"              
[15] "Croatia, Rep. of"         "Cyprus"                  
[17] "Czech Rep."               "Denmark"                 
[19] "Estonia, Rep. of"         "Finland"                 
[21] "France"                   "Germany"                 
[23] "Greece"                   "Hungary"                 
[25] "Iceland"                  "India"                   
[27] "Indonesia"                "Ireland"                 
[29] "Israel"                   "Italy"                   
[31] "Japan"                    "Kazakhstan, Rep. of"     
[33] "Korea, Rep. of"           "Lao People's Dem. Rep."  
[35] "Latvia"                   "Lithuania"               
[37] "Luxembourg"               "Malaysia"                
[39] "Malta"                    "Mexico"                  
[41] "Morocco"                  "Myanmar"                 
[43] "Netherlands, The"         "New Zealand"             
[45] "Norway"                   "Peru"                    
[47] "Philippines"              "Poland, Rep. of"         
[49] "Portugal"                 "Rest of the World"       
[51] "Romania"                  "Russian Federation"      
[53] "Saudi Arabia"             "Singapore"               
[55] "Slovak Rep."              "Slovenia, Rep. of"       
[57] "South Africa"             "Spain"                   
[59] "Sweden"                   "Switzerland"             
[61] "Taiwan Province of China" "Thailand"                
[63] "Tunisia"                  "Turkey"                  
[65] "United Kingdom"           "United States"           
[67] "Vietnam"                 
Code
tail(co2_longer)
# A tibble: 6 × 5
  year  country country_code indicator                 metric_tons_millions
  <chr> <chr>   <chr>        <fct>                                    <dbl>
1 2021  Vietnam VNM          co2_production                             NA 
2 2021  Vietnam VNM          co2_final_domestic_demand                  NA 
3 2021  Vietnam VNM          co2_final_demand_balance                   NA 
4 2021  Vietnam VNM          co2_gross_exports                         420.
5 2021  Vietnam VNM          co2_gross_imports                         227.
6 2021  Vietnam VNM          co2_gross_exports_balance                 193.

The (renamed) Indicator values represent CO2 Emissions embodied in production, CO2 Emissions embodied in final domestic demand, the balance of CO2 Emissions embodied in final demand, CO2 Emissions embodied in gross exports, CO2 Emissions embodied in gross imports, and the balance of CO2 Emissions embodied in gross exports. To summarize, this data tracks how much CO2 is emitted by, consumed by, and embodied in trade between different countries. Negative values for demand balance and gross exports balance indicate the country’s demand is higher than its production and its imports are greater than its exports, respectively.

Code
unique(co2_longer$indicator)
[1] co2_production            co2_final_domestic_demand
[3] co2_final_demand_balance  co2_gross_exports        
[5] co2_gross_imports         co2_gross_exports_balance
6 Levels: co2_final_demand_balance ... co2_production

Descriptive statistics

Compute descriptive statistics on the variables of interest (i.e., mean, median, sd for numerical variables, counts and proportions for categorical variables)

We can group the data by year and find the mean, median, max and standard deviation for CO2 emissions embodied in production.

Code
co2_longer %>%
  filter(indicator == "co2_production") %>%
  group_by(year) %>%
  summarise(mean = mean(metric_tons_millions), median=median(metric_tons_millions), max=max(metric_tons_millions), sd=sd(metric_tons_millions))
# A tibble: 27 × 5
   year   mean median   max    sd
   <chr> <dbl>  <dbl> <dbl> <dbl>
 1 1995   319.   62.2 5153.  773.
 2 1996   326.   67.3 5310.  786.
 3 1997   332.   72.4 5580.  815.
 4 1998   334.   70.1 5626.  824.
 5 1999   336.   69.6 5648.  824.
 6 2000   347.   69.9 5820.  852.
 7 2001   352.   69.8 5779.  859.
 8 2002   357.   70.0 5631.  862.
 9 2003   372.   75.6 5696.  904.
10 2004   390.   77.7 5803.  962.
# ℹ 17 more rows

We can also find the greatest emitters and consumers of CO2 emissions of all time. We can see that Mainland China has produced and consumed the most CO2 emissions compared to any other country, even when compared to all countries not included in this study combined (Rest of World).

Code
co2_longer %>%
  filter(indicator == "co2_production")%>%
  arrange(desc(metric_tons_millions)) %>%
  slice(1:5)
# A tibble: 5 × 5
  year  country               country_code indicator      metric_tons_millions
  <chr> <chr>                 <chr>        <fct>                         <dbl>
1 2018  China, P.R.: Mainland CHN          co2_production                9916.
2 2017  China, P.R.: Mainland CHN          co2_production                9503.
3 2014  China, P.R.: Mainland CHN          co2_production                9302.
4 2013  China, P.R.: Mainland CHN          co2_production                9298.
5 2016  China, P.R.: Mainland CHN          co2_production                9277.
Code
co2_longer %>%
  filter(indicator == "co2_final_domestic_demand")%>%
  arrange(desc(metric_tons_millions)) %>%
  slice(1:5)
# A tibble: 5 × 5
  year  country               country_code indicator        metric_tons_millions
  <chr> <chr>                 <chr>        <fct>                           <dbl>
1 2018  China, P.R.: Mainland CHN          co2_final_domes…                9020.
2 2017  China, P.R.: Mainland CHN          co2_final_domes…                8558.
3 2016  China, P.R.: Mainland CHN          co2_final_domes…                8407.
4 2015  China, P.R.: Mainland CHN          co2_final_domes…                8322.
5 2014  China, P.R.: Mainland CHN          co2_final_domes…                8231.

We can also find countries that are below the median for consuming products of CO2 emissions.

Code
co2_longer %>%
  filter(year == 2018 & indicator == "co2_final_domestic_demand")%>%
  group_by(year) %>%
  filter(metric_tons_millions < median(metric_tons_millions)) %>%
  arrange(metric_tons_millions)
# A tibble: 33 × 5
# Groups:   year [1]
   year  country                country_code indicator      metric_tons_millions
   <chr> <chr>                  <chr>        <fct>                         <dbl>
 1 2018  Malta                  MLT          co2_final_dom…                 4.16
 2 2018  Iceland                ISL          co2_final_dom…                 4.34
 3 2018  Brunei Darussalam      BRN          co2_final_dom…                 8.57
 4 2018  Cyprus                 CYP          co2_final_dom…                 9.08
 5 2018  Latvia                 LVA          co2_final_dom…                10.5 
 6 2018  Lao People's Dem. Rep. LAO          co2_final_dom…                11.9 
 7 2018  Luxembourg             LUX          co2_final_dom…                13.0 
 8 2018  Costa Rica             CRI          co2_final_dom…                13.9 
 9 2018  Estonia, Rep. of       EST          co2_final_dom…                14.3 
10 2018  Cambodia               KHM          co2_final_dom…                14.9 
# ℹ 23 more rows

Top CO2 Producers 2018 and 1995

We can also pivot the data wider so each row describes the emissions of 1 country for 1 year.

Code
co2_wider <- co2_longer %>%
  # Omit years with estimates and incomplete data
  filter(! year %in% c(2019,2020,2021)) %>%
  # New columns for different indicators
  pivot_wider(names_from = indicator, values_from = metric_tons_millions)

Using the wider data frame, we can find the highest producers for 2018.

Code
max_prod_countries_2018 <- co2_wider %>%
  # Filter only 2018 values
  filter(year == 2018) %>%
  # Sort descending on CO2 from production
  arrange(desc(co2_production)) %>%
  # Grab the top 5
  slice(1:5) %>%
  # Send countries to a vector to use later
  pull(country)

Using the above calculations, we can graph the highest producers of CO2 and how their emissions have changed from 1995 to 2018. We have already seen that Mainland China is the highest produced of CO2 emissions of all time, and the graph below shows that their emissions have nearly quadrupled during the period of study. It is interesting to see that the United States was the highest producer in the group in 1995, but we have actually slightly decreased our CO2 emissions embodied in production over the past 20 years. The Rest of World and India have seen marginal increases in their production emissions while Russia has experienced only a slight increase.

Code
co2_wider %>%
  filter((year == 2018 | year == 1995) & country %in% max_prod_countries_2018) %>%
  arrange(desc(year), desc(co2_production)) %>%
  ggplot(aes(x = reorder(country, -co2_production), y = co2_production, fill = year)) +
  geom_bar(stat = "identity", position = 'dodge') + 
  labs(x = "Country", y = "CO2 Emissions Embodied in Production", title = "Top CO2 Emitters from Production", subtitle = "1995 vs 2018", fill = "Year") +
  theme_linedraw() +
  theme(plot.title = element_text(hjust = 0.5),plot.subtitle = element_text(hjust = 0.5), legend.key = element_rect(color = "black")) + 
  scale_fill_manual(values=c( "tomato", "steelblue3"))

Global CO2 Emissions Over Time

A good data point to see is how CO2 emissions have changed over time. If we group the data by year, we can calculate the total amount of emissions encapsulated by each Indicator. Once we have the totals, we can graph each Indicator value by year and it shows that there is a steady trend of increasing emissions of all types over time, with a slight downtrend from 2008 to 2009. This could perhaps be due to the 2008 financial crisis which impacted global industrial production and consumption.

Code
total_co2_by_year <- co2_wider %>%
  # Group by year
  group_by(year) %>%
  # Calculate totals for each indicator
  summarise(total_prod = sum(co2_production, na.rm = TRUE), total_demand = sum(co2_final_domestic_demand, na.rm = TRUE), total_export = sum(co2_gross_exports, na.rm = TRUE), total_imports = sum(co2_gross_imports, na.rm =TRUE)) %>%
  ungroup() %>%
  # Pivot longer again for easy evolution graph
  pivot_longer(cols = 2:5  , names_to = "indicator", values_to = "value") 
   
total_co2_by_year %>% 
  ggplot(aes(year, value, fill=indicator)) + geom_bar(stat = "identity") +scale_x_discrete(breaks=seq(1995, 2020,5)) +
  labs(x = "Year", y = "CO2 Emissions (Metric tons, millions)", title = "CO2 Emissions over Time", subtitle = "1995 - 2018", fill = "Emissions Indicator") +
  theme_classic() + 
  theme(plot.title = element_text(hjust = 0.5),plot.subtitle = element_text(hjust = 0.5), legend.key = element_rect(color = "black")) 

CO2 Production vs Demand

Is there any pattern showing the relationship between the production and consumption of CO2 emissions? Using our wider data frame, we can graph co2_demand against co2_production and end up with a nice scatter plot showing the dispersion of different countries throughout the years. The graph indicates that there is a very close relationship where higher demand will result in higher levels of emissions from production. A majority of countries seem to be right on our regression line of a 1-1 relationship between the two, but as the values increase there are more data points with some variance between those values. It is interesting that the countries with data points above the regression line can be classified as net-exporters, as they produce more than they consume. The products from their excess production have been exported to the net-importers, being the countries that lay below the regression line, where they demand more than they produce and that has to come from somewhere.

Code
co2_wider %>%
  ggplot(aes(co2_final_domestic_demand, co2_production)) + geom_point()  + geom_smooth(method = "lm") + 
  labs(x = "CO2 Emissions Embodied in Domestic Demand", y = "CO2 Emissions Embodied in Production", title = "CO2 Emissions, Production vs Demand") +
  theme_bw() + theme(plot.title = element_text(hjust = 0.5))
`geom_smooth()` using formula = 'y ~ x'

Considering the pattern of net-importers and net-exporters we can examine the history of 4 major countries United States, United Kingdom, Australia and China. If we plot their individual CO2 production and demand over time, using facet_wrap to get individual bar graphs for each country we can see which are predominantly importers or exporters. China has always been a net-exporter given that its production outweighs its domestic demands. Australia has gone back and forth, initially being a net-exporter, but has been a net-importer since around 2004. The UK and the US have always been net-importers, having their demand higher than production, consuming the products as a result of CO2 emissions that were produced elsewhere.

Code
countries <- c('United States', 'Australia', 'China, P.R.: Mainland', 'United Kingdom')
co2_longer %>%
  filter(indicator %in% c('co2_production', 'co2_final_domestic_demand') & country %in% countries) %>%
  ggplot(aes(year, metric_tons_millions)) +
  geom_bar(stat="identity", position = 'dodge', aes(fill=indicator)) + facet_wrap(vars(country), scales = "free") +
  scale_x_discrete(breaks=seq(1995, 2018,5)) +
  theme_dark() + 
  theme(plot.title = element_text(hjust = 0.5), legend.position="bottom", legend.key = element_rect(color = "black")) +
  labs(x = "Year", y= "CO2 Emissions, millions of metric tons", title = "Production, Demand CO2 Emissions")
Warning: Removed 24 rows containing missing values (`geom_bar()`).

CO2 Emissions with Population Data Set

Does the population size of a country affect the way we view CO2 emissions? For this analysis we would need to join our emissions data with another data set that includes that information. I will be using the populations.csv data set retrieved from the World Bank.

This data set lists the population of countries around the world from 1960 to 2022. We can match the ISO3 country code and year to do an inner_join with the CO2 emissions data set so that we have all the original data, now with population sizes.

If we investigate the results after the join, we see that only 2 regions, “Rest of World” and “Taiwan Province of China”, are left without data so that is a pretty good result. We can omit them from the comparison and should be able to calculate per capita CO2 emissions.

Code
# Read in populatio data set
pop <- read_csv(here("data", "populations.csv"), skip=4)
New names:
Rows: 266 Columns: 68
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(4): Country Name, Country Code, Indicator Name, Indicator Code dbl (63): 1960,
1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, ... lgl (1): ...68
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...68`
Code
head(pop)
# A tibble: 6 × 68
  `Country Name`  `Country Code` `Indicator Name` `Indicator Code` `1960` `1961`
  <chr>           <chr>          <chr>            <chr>             <dbl>  <dbl>
1 Aruba           ABW            Population, tot… SP.POP.TOTL      5.46e4 5.58e4
2 Africa Eastern… AFE            Population, tot… SP.POP.TOTL      1.31e8 1.34e8
3 Afghanistan     AFG            Population, tot… SP.POP.TOTL      8.62e6 8.79e6
4 Africa Western… AFW            Population, tot… SP.POP.TOTL      9.73e7 9.93e7
5 Angola          AGO            Population, tot… SP.POP.TOTL      5.36e6 5.44e6
6 Albania         ALB            Population, tot… SP.POP.TOTL      1.61e6 1.66e6
# ℹ 62 more variables: `1962` <dbl>, `1963` <dbl>, `1964` <dbl>, `1965` <dbl>,
#   `1966` <dbl>, `1967` <dbl>, `1968` <dbl>, `1969` <dbl>, `1970` <dbl>,
#   `1971` <dbl>, `1972` <dbl>, `1973` <dbl>, `1974` <dbl>, `1975` <dbl>,
#   `1976` <dbl>, `1977` <dbl>, `1978` <dbl>, `1979` <dbl>, `1980` <dbl>,
#   `1981` <dbl>, `1982` <dbl>, `1983` <dbl>, `1984` <dbl>, `1985` <dbl>,
#   `1986` <dbl>, `1987` <dbl>, `1988` <dbl>, `1989` <dbl>, `1990` <dbl>,
#   `1991` <dbl>, `1992` <dbl>, `1993` <dbl>, `1994` <dbl>, `1995` <dbl>, …
Code
pop_longer <- pop %>%
  # Pivot data longer so each row contains population size of 1 country for 1 year
  pivot_longer(cols = 5:67  , names_to = "year", values_to = "population") %>%
  # Select relevant columns
  select(year, "Country Code", population) %>%
  # Rename columns
  rename(country_code = "Country Code")

# Join population data frame with co2, matching on country_code and year
co2_population <- co2_wider %>% left_join(pop_longer, by=c("country_code","year"))

# Examine results with no data
tmp_no_pop <- co2_population %>% filter(is.na(population)) 
unique(tmp_no_pop$country)
[1] "Rest of the World"        "Taiwan Province of China"

We can mutate the new data frame to include a column for the CO2 emissions embodied in production per capita. Using this new value we can filter down the results to the highest producers per capita for 2018 and plot them. This graph levels the playing field in terms of just total emissions and there are some interesting findings. Singapore is the highest CO2 emitter per capita via production which I would never thought of. This is attributed by its relatively small population size, roughly 5.6 million, compared to that of the US which is over 326 million. This graph gives a nice view into how much emissions countries are producing relative to its population size rather than just strict totals.

Code
co2_per_capita <- co2_population %>% 
  # Calculate co2 production per capita. Multiplying by 1 mil for unit conversion
  mutate(production_per_capita = co2_production/population * 1000000) 

co2_per_capita %>%
  # Filter 2018
  filter(year == 2018) %>%
  # Sort descending by per capita
  arrange(desc(production_per_capita)) %>%
  # Take top 15 
  slice(1:15) %>%
  ggplot( aes(production_per_capita,y = reorder(country, production_per_capita), fill=country)) + 
  geom_bar(stat="identity", fill = "grey27") +
  geom_text(aes(label = round(production_per_capita, digits=2)),hjust = 1.2, vjust = .5, color="white") + 
  labs(x = "CO2 Emissions per Capita (metric tons)", title = "2018 CO2 Emissions per Capita", y ="") + 
  theme(panel.background = element_rect(fill = "darkolivegreen4")) +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_x_continuous(breaks=seq(0, 30,5))

If we compare the prominent countries from before, United States, Australia, China, P.R.: Mainland, and United Kingdom, we can graph their CO2 emissions per capita over time. This will give us a better idea of how countries have been doing in controlling their emissions with respect to their population sizes. The United States was the highest emitter per capita of the group in 1995, but has seen a steady decline since around 2000 and now sits lower than Australia. Australia and the UK have followed similar patterns of some initial increase but a somewhat consistent decrease in emissions over the past 10 years. China has followed the opposite pattern, where it started with the least CO2 emissions per capita but has been they have been on the rise and finally surpassed the UK around 2015. .

Code
co2_per_capita$year <- as.numeric(as.character(co2_per_capita$year))

co2_per_capita %>%
  # Include countries in our sample
  filter( country %in% countries) %>%
  ggplot(aes(year, production_per_capita, col=country)) + geom_path(linewidth=1) +
  labs(x = "Year",  y ="CO2 Emissions per Capita (metric tons)", title = "CO2 Emissions per Capita over Time")+
  theme_dark() + theme(plot.title = element_text(hjust = 0.5)) +  
  theme(panel.background = element_rect(fill = "grey27"),legend.key = element_rect(color = "black"))