Week 8 HW

Author

Andrew George

Loading libraries and data

library(dslabs)
Warning: package 'dslabs' was built under R version 4.3.3
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(scales)

Attaching package: 'scales'

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

    discard

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

    col_factor
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

Attaching package: 'highcharter'

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

    stars
data("temp_carbon")
view(temp_carbon)

Removing Na’s

carbon2 <- temp_carbon |>
  filter(!is.na(ocean_anomaly) & !is.na(carbon_emissions & !is.na(land_anomaly))) 

Creating the graph

colors <- c("blue", "darkgreen", "black")
highchart() |>
  hc_yAxis_multiples(
    list(title = list(text = "Carbon Emissions (Millions of metric tons)")),
    list(title = list(text = "Temperature Anomaly (C)"),
         opposite = TRUE)
  ) |>
  hc_add_series(data = carbon2$ocean_anomaly,
                name = "Ocean Anomaly",
                type = "area",
                yAxis = 1) |>
  hc_add_series(data = carbon2$land_anomaly,
                name = "Land Anomoly",
                type = "area",
                yAxis = 1) |>
  hc_add_series(data = carbon2$carbon_emissions,
                name = "Carbon Emissions",
                type = "line",
                yAxis = 0) |>
  hc_xAxis(categories = carbon2$year,
           tickInterval = 6) |>
  hc_xAxis(title = list(text="Year")) |>
  hc_title(text = "Carbon Emissions and Temperature Anomalies") |>
  hc_colors(colors) |>
  hc_chart(style = list(fontFamily = "Georgia",
                        fontWeight = "bold")) |>
  hc_legend(verticalAlign = "top",
            layout = "horizontal")

Essay

I used the “temp_carbon” data set from DS labs. I chose this data set to explore the different temperature anomalies versus carbon emissions. The graph shows that as carbon emissions started increasingly going up, generally both land and ocean anomalies also went up. Using y multiples I added multiple hc series for each of my variables and assigned them to their corresponding y axises. I used the type area for the anomaly variables to illustrate when the anomalies dipped below and above average. This helps to show that since 1976 there have been no negative land or ocean temperature anomalies. I then added my x axis label and a title. Finally, I customized my graph by using my own colors, moving the legend upwards and by changing the font.