W8-HW-DSLabs

Author

ZS

Document setup

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.5.1     ✔ 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(dslabs)
library(highcharter)
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 

Attaching package: 'highcharter'

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

    stars

Visualization

data("temp_carbon")
temp_carbon <- temp_carbon|>filter(year>=1880 & year<2016)
highchart()|>
  hc_yAxis_multiples(
    list(title = list(text = "Mean Temp. Anomaly, Relative to 20th Century (Celsius)")),
    list(title = list(text = "Carbon Emmissions (Mil. Metric Tons)"),
         opposite = TRUE)
  ) |>
  hc_add_series(data = temp_carbon$temp_anomaly,
                name = "Global Temperature Anomaly",   
                type = "line",
                yAxis=0) |>
  hc_add_series(data = temp_carbon$ocean_anomaly,
                name = "Ocean Temperature Anomaly",   
                type = "line",
                yAxis=0) |>
  hc_add_series(data = temp_carbon$land_anomaly,
                name = "Land Temperature Anomaly",   
                type = "line",
                yAxis=0) |>
  hc_add_series(data = temp_carbon$carbon_emissions,
                name = "Carbon Emmissions",
                type = "line",
                yAxis = 1) |>
  hc_xAxis(categories = temp_carbon$year, title = list(text="Year")) |>
  hc_title(text="Temperature Anomaly & Carbon Emissions, 1880-2015")|>
  hc_plotOptions(series = list(marker = list(symbol = "circle"))) |>
   hc_tooltip(shared = TRUE,
             borderColor = "black")|>
  hc_add_theme(hc_theme_smpl())

Description

I used the temp_carbon dataset, which contains global carbon emissions from 1751-2014 and global temperature anomalies from 1880-2018. I used highcharter to plot the mean global temperature anomaly and carbon emissions on separate y-axis scales. I attempted to plot the three categories of anomalies instead of just the global temperature, but haven’t yet figured it out, which is why there’s some code that’s been commented out.