DSLabs HW

Author

Michael Desir

Load libraries/data

library(tidyverse)
library(highcharter)
library(dslabs)
library(devtools)
data("greenhouse_gases")

Separate gases into respective dataframes

co2_data <- greenhouse_gases %>%
  slice(1:100)
ch4_data <- greenhouse_gases %>%
  slice(101:200)
n2o_data <- greenhouse_gases %>%
  slice(201:300)

Design plot

paints <- c("skyblue","violet")
highchart() |>
  hc_title(text = "Concentrations of Methane and Carbon Dioxide, 20 A.D. to 2000",
           style = list(color = "#EEE9E9")) |>
  hc_yAxis_multiples(
    list(title = list(text = "Carbon Dioxide Concentration (ppm))")),
    list(title = list(text = "Methane Concentration (ppb)"),opposite=TRUE)
  ) |>
  hc_add_series(data = co2_data$concentration,
                name = "Carbon Dioxide Concentration (ppm))",
                type = "line",
                yAxis = 0) |>
  hc_add_series(data = ch4_data$concentration,
                name = "Methane Concentration (ppb)",
                type = "line",
                yAxis = 1) |>
  hc_xAxis(categories = ch4_data$year,
           tickInterval = 10,
           title=list(text = "Year")) |>
  hc_colors(paints) |>
  hc_chart(style = list(fontFamily = "Courier",
                        fontWeight = "bold",
                        fontSize = "15px")) |>
  hc_legend(
    align = "left",
    verticalAlign = "top",
    layout = "vertical",
    x = 0,
    y = 200,
    backgroundColor = "#EEE9E9"
  ) |>
  hc_add_theme(hc_theme(chart = list(backgroundColor = 'black')))

Write-up

For this assignment, I selected the greenhouse_gases dataset from the DSLabs package. The first thing I did was manually splitting the dataset into one dataset for each gas. Considering that these dataset compared a few variables over time with equal intervals, I decided that a line plot would suffice. I opted to use highcharter so I could get some experience with it. What I ended up finding out is that not only is this package very easy to use, it is also highly customizable. There are a lot of things I could’ve done, but I only did a few. The first thing I tried was adding a third y-axis to map nitrogen oxide, but didn’t like the way it looked so I deleted it. I then changed the graph’s font to Courier, one of my preferred fonts. I also customized the legend, added text to the x-axis and changed the background color. My best friend here was the documentation, which I found highly intuitive and useful.