In this work, I looked at the greenhouse concentrations over the years and saw the patterns in the increases and decreases of all the gases.

First install the necessary packages, and since “dslabs” contains our dataset installing it will be a priority.

# install.packages("dslabs")
library("dslabs")

Loading in the other packages

data("greenhouse_gases")

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.4     ✓ purrr   0.3.4
## ✓ tibble  3.1.2     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(ggplot2)
library(ggthemes)
library(dplyr)

str(greenhouse_gases)
## 'data.frame':    300 obs. of  3 variables:
##  $ year         : num  20 40 60 80 100 120 140 160 180 200 ...
##  $ gas          : chr  "CO2" "CO2" "CO2" "CO2" ...
##  $ concentration: num  278 278 277 277 278 ...
# greenhouse_gases

After examining the the dataset, I saw that there were 3 different greenhouse gases and that the dataset started in the year 20 CE. This may become an issue later on.

Filtering Unnecessary Categories]

CH4 is measured in ppb and its relative numerical values are significantly higher than both CO2 (ppm) and N2O (ppb). Therefore, CH4 will need to be filtered out or the other categories will look like they have no meaning.

green1<- greenhouse_gases %>%
  filter(gas != "CH4")

Creating the First Scatterplot

Even though the concentration values of CO2 and N2O are different (ppm and ppb), we are only looking at the patterns of the increases and decreases. Therefore, they will be put on the same graph for the comparison of the trend, not the exact numbers.

p3 <- ggplot(data = green1, aes(x = year, y = concentration)) +
  geom_point(aes(color = gas)) +
  scale_color_manual(name = "Gases", values = c("red", "lightblue", "green")) +
  ggtitle("Greenhouse Gas Concetrations Over the Years") +
  theme(plot.title = element_text(hjust = 0.50)) +
  labs(
    x = "Year",
    y = "Concentration (ppm for CO2 and ppb for N2O)")
  
p3

Immediately, we can see that there was a significant increase in both CO2 and N2O concentrations at around the same time. But this graph does not give us a good idea of when. Therefore we will need to filter the data further for a closer look.

Filtering the data further

I chose to filter out data before the year 1700 inclusive as the concnetration before then seemed relatively the same.

green <- greenhouse_gases %>%
  filter(gas != "CH4", year >= 1700)

noCH4 <- green %>%
  arrange(desc(year))

# noCH4

Creating the Modified Scatterplot

The Industrial Revolution started at around 1760, so I added a vertical line indicating its start at that x value.

p1 <- ggplot(data = noCH4, aes(x = year, y = concentration)) +
  geom_point(aes(color = gas)) +
  stat_smooth(aes(color = gas), method = "lm", 
              formula = y ~ poly(x, 2),  se = FALSE) +
  scale_color_manual(name = "Gases", values = c("red", "lightblue")) +
  ggtitle("Greenhouse Gas Concetrations Over the Years Starting from 1700") +
  geom_vline(xintercept = 1760, linetype = "dashed", color = "black") +
  theme(plot.title = element_text(hjust = 0.50)) +
  labs(
    x = "Year",
    y = "Concentration (ppm for CO2 and ppb for N2O)")
  
p1

So, both gases seem to have a similar pattern. After the year 1760, the concentration of both gases sky rocketed significantly. But what about methane (CH4)? Does it have a similar pattern? I decided to take a look separately:

Filtering Out Years and Gases for Only CH4 After 1700 Inclusive

CH4 <- greenhouse_gases %>%
  filter(gas == "CH4", year > 1700)

CH4
##    year gas concentration
## 1  1720 CH4         667.0
## 2  1740 CH4         706.5
## 3  1760 CH4         700.0
## 4  1780 CH4         718.2
## 5  1800 CH4         726.6
## 6  1820 CH4         739.5
## 7  1840 CH4         765.9
## 8  1860 CH4         786.2
## 9  1880 CH4         826.5
## 10 1900 CH4         865.0
## 11 1920 CH4         957.3
## 12 1940 CH4        1062.8
## 13 1960 CH4        1205.5
## 14 1980 CH4        1495.3
## 15 2000 CH4        1703.4

Creating the Graph for Methane

p2 <- ggplot(data = CH4, aes(x = year, y = concentration)) +
  geom_point(aes(color = gas)) +
  stat_smooth(aes(color = gas), method = "lm",
              formula = y ~ poly(x, 2), se = FALSE) +
  scale_color_manual(name = "Gas", values = c("#566C74")) +
  ggtitle("Methane Concentration Over the Years Starting from 1700") +
  geom_vline(xintercept = 1760, linetype = "dashed", color = "black") +
  theme(plot.title = element_text(hjust = 0.50)) +
  labs(
    x = "Year",
    y = "Concentration (ppb)")
  
p2

As you cans see, the graph for CH4 has a similar trend as well. Even though its values are significantly higher, the pattern is still the same nonetheless.

Conclusion

Overall, the three major greenhouse gases Carbon Dioxide (CO2), Nitrous Oxide (N2O), and Methane (CH4) have increased singificantly in atmospheric concentration over the last couple of years. Ever since the Industrial Revolution, these increases are more noticeable. Although these graphs do not prove it, it can be inferred that the increase in these gases (along with many others) have attributed to the climate change over the past 3 centuries.