library("dslabs") 
library(tidyverse)
## ── Attaching packages ───────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.2.0     ✔ purrr   0.3.2
## ✔ tibble  2.1.3     ✔ dplyr   0.8.3
## ✔ tidyr   0.8.3     ✔ stringr 1.4.0
## ✔ readr   1.3.1     ✔ forcats 0.4.0
## ── Conflicts ──────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(matrixStats)
## 
## Attaching package: 'matrixStats'
## The following object is masked from 'package:dplyr':
## 
##     count
#data(package="dslabs") 
#list.files(system.file("script", package = "dslabs")) 

# set colorblind-friendly color palette
colorblind_palette <- c("black", "#E69F00", "#56B4E9", "#009E73", "#CC79A7", "#F0E442", "#0072B2", "#D55E00")

The dataset selected was temp_carbon, since I am enviromental conscious and it is disheartening what is happening to our Earth. In the current political arena especially in the US, money is TRUMPing statistical and scientific proof that Climate Change is a reality, rather than a hoax.

For example, as the climate warms, it changes the nature of global rainfall, snow, and other factors that affect water supply and quality.

data(temp_carbon)
#view(temp_carbon)
 
str(temp_carbon)
## 'data.frame':    268 obs. of  5 variables:
##  $ year            : num  1880 1881 1882 1883 1884 ...
##  $ temp_anomaly    : num  -0.11 -0.08 -0.1 -0.18 -0.26 -0.25 -0.24 -0.28 -0.13 -0.09 ...
##  $ land_anomaly    : num  -0.48 -0.4 -0.48 -0.66 -0.69 -0.56 -0.51 -0.47 -0.41 -0.31 ...
##  $ ocean_anomaly   : num  -0.01 0.01 0 -0.04 -0.14 -0.17 -0.17 -0.23 -0.05 -0.02 ...
##  $ carbon_emissions: num  236 243 256 272 275 277 281 295 327 327 ...
dim(temp_carbon)
## [1] 268   5
head(temp_carbon)
##   year temp_anomaly land_anomaly ocean_anomaly carbon_emissions
## 1 1880        -0.11        -0.48         -0.01              236
## 2 1881        -0.08        -0.40          0.01              243
## 3 1882        -0.10        -0.48          0.00              256
## 4 1883        -0.18        -0.66         -0.04              272
## 5 1884        -0.26        -0.69         -0.14              275
## 6 1885        -0.25        -0.56         -0.17              277
tail(temp_carbon)
##     year temp_anomaly land_anomaly ocean_anomaly carbon_emissions
## 263 1874           NA           NA            NA              174
## 264 1875           NA           NA            NA              188
## 265 1876           NA           NA            NA              191
## 266 1877           NA           NA            NA              194
## 267 1878           NA           NA            NA              196
## 268 1879           NA           NA            NA              210

Annual mean global temperature anomaly on land, sea and combined, 1880-2018. Annual global carbon emissions, 1880 - 2018 relative to the 20th century mean temperature from 1880-2018. The temperature anomalies over land and over ocean are reported also.

Temperature anomaly is the difference from an average/baseline temperature; - baseline temp =c omputed by averaging 30 or more years of temperature data. - positve anomaly = observed temperature is warmer than the baseline. - negative anomaly = observed temperature is cooler than the baseline.

Note: Year 1751 to 1876 have been removed because they have no data reported.

Source: NOAA

data(temp_carbon)
#view(temp_carbon)

# line plot of annual global, land and ocean temperature anomalies since 1880
temp_carbon %>%
    select(Year = year, Global = temp_anomaly, Land = land_anomaly, Ocean = ocean_anomaly) %>%
    gather(Region, Temp_anomaly, Global:Ocean) %>%
    ggplot(aes(Year, Temp_anomaly, col = Region)) +
    geom_line(size = 1) +
    geom_hline(aes(yintercept = 0), col = colorblind_palette[8], lty = 2) +
    geom_label(aes(x = 2005, y = -.08), col = colorblind_palette[8],label = "20th century mean", size = 4) +
    ylab("Temperature anomaly (degrees C)") +
    xlim(c(1880, 2018)) +
    scale_color_manual(values = colorblind_palette) +
    ggtitle("Temperature anomaly relative to 20th century mean, 1880-2018")
## Warning: Removed 387 rows containing missing values (geom_path).

Since 1751 just over 400 billion metric tonnes of carbon have been released to the atmosphere from the consumption of fossil fuels and cement production. Half of these fossil-fuel CO2 emissions have occurred since the late 1980s. The 2014 global fossil-fuel carbon emission estimate, 9855 million metric tons of carbon, represents an all-time high and a 0.8% increase over 2013 emissions. The slight increase continues a three-year trend of modest annual growth under 2% per year. This modest growth comes on the heels of a quick recovery from the 2008-2009 Global Financial Crisis which had obvious short-term economic and energy use consequences, particularly in North America and Europe.

Globally, liquid and solid fuels accounted for 75.1% of the emissions from fossil-fuel burning and cement production in 2014. Combustion of gas fuels (e.g., natural gas) accounted for 18.5% (1823 million metric tons of carbon) of the total emissions from fossil fuels in 2014 and reflects a gradually increasing global utilization of natural gas. Emissions from cement production (568 million metric tons of carbon in 2014) have more than doubled in the last decade and now represent 5.8% of global CO2 releases from fossil-fuel burning and cement production. Gas flaring, which accounted for roughly 2% of global emissions during the 1970s, now accounts for less than 1% of global fossil-fuel releases.

Sources: Boden et al., 2017 via CDIAC.

# line plot of anthropogenic carbon emissions over 250+ years
temp_carbon %>%
  ggplot(aes(year, carbon_emissions)) +
  geom_line() +
  xlab("Year") +
  ylab("Carbon emmissions (metric tons)") +
  ggtitle("Annual global carbon emmissions, 1751-2014")
## Warning: Removed 4 rows containing missing values (geom_path).