Temperature and Carbon Emissions

Author

Al

Source: US National Archive

The data used is found in the dslabs package. It documents annual mean global temperature anomalies on land, sea, and overall for the years 1880-2018. It also includes the annual global carbon emissions for the years 1751-2014.

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(highcharter)
Warning: package 'highcharter' was built under R version 4.3.3
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
Highcharts (www.highcharts.com) is a Highsoft software product which is
not free for commercial and Governmental use
library("dslabs")
Warning: package 'dslabs' was built under R version 4.3.3

Attaching package: 'dslabs'

The following object is masked from 'package:highcharter':

    stars

It comes from the NOAA and CDIAC.

data("temp_carbon")
summary(temp_carbon)
      year       temp_anomaly     land_anomaly      ocean_anomaly     
 Min.   :1751   Min.   :-0.450   Min.   :-0.69000   Min.   :-0.46000  
 1st Qu.:1818   1st Qu.:-0.180   1st Qu.:-0.31500   1st Qu.:-0.17000  
 Median :1884   Median :-0.030   Median :-0.05000   Median :-0.01000  
 Mean   :1884   Mean   : 0.060   Mean   : 0.07086   Mean   : 0.05273  
 3rd Qu.:1951   3rd Qu.: 0.275   3rd Qu.: 0.30500   3rd Qu.: 0.25500  
 Max.   :2018   Max.   : 0.980   Max.   : 1.50000   Max.   : 0.79000  
                NA's   :129      NA's   :129        NA's   :129       
 carbon_emissions 
 Min.   :   3.00  
 1st Qu.:  13.75  
 Median : 264.00  
 Mean   :1522.98  
 3rd Qu.:1431.50  
 Max.   :9855.00  
 NA's   :4        

A bubble graph will be used to explore the relationship between temperature anomalies and carbon emissions.

#filtering out all of the NAs in the data
temp_carbon2 <- filter(temp_carbon, 
                       !is.na(temp_anomaly) & 
                       !is.na(land_anomaly) & 
                       !is.na(ocean_anomaly) & 
                       !is.na(carbon_emissions))

#Highcharter bubble chart
highchart() |>
  hc_add_series(data = temp_carbon2,
         type = "bubble",
         hcaes(x = land_anomaly, 
               y = ocean_anomaly, 
               colorAxis = carbon_emissions, 
               size = temp_anomaly),
         maxSize = 35, minSize = 2) |>
  hc_colorAxis(showInLegend = TRUE,
               minColor = "blue", maxColor = "red",
               min = 0) |>
  
  hc_xAxis(title = list(text="Annual Mean Temperature Anomaly over Land (°C)"), 
           max = 1.3, min = -0.8, tickInterval = 0.2) |>
  hc_yAxis(title = list(text="Annual Mean Temperature Anomaly over Ocean (°C)"),
           max = 0.8, min = -0.7, tickInterval = 0.2) |>
  
  hc_tooltip(pointFormat = 
               "{point.year}: {point.carbon_emissions} millions of metric tons",
             headerFormat = " ") |>
  hc_title(text="Temperature Anomalies and Carbon Emissions ", 
           align = "center") |>
  hc_subtitle(text="1751-2018", align = "center") |>
  hc_legend(enabled = TRUE, floating = TRUE,
            x = 0, y = -120,
            border = TRUE, borderWidth = 2, 
            borderColor = "lightblue", backgroundColor = "white",
            title = list(text="Annual Carbon Emissions (MMT)")) |>
  hc_caption(text = 
               "Source: NOAA and Boden, T.A., G. Marland, and R.J. Andres (2017) via CDIAC") |>
  hc_add_theme(hc_theme_ffx())