HW DSLABS- Vietnam War

Author

Allan Maino Vieytes

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

Attaching package: 'highcharter'

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

    stars
data(gapminder)
head(gapminder)
              country year infant_mortality life_expectancy fertility
1             Albania 1960           115.40           62.87      6.19
2             Algeria 1960           148.20           47.50      7.65
3              Angola 1960           208.00           35.98      7.32
4 Antigua and Barbuda 1960               NA           62.97      4.43
5           Argentina 1960            59.87           65.39      3.11
6             Armenia 1960               NA           66.86      4.55
  population          gdp continent          region
1    1636054           NA    Europe Southern Europe
2   11124892  13828152297    Africa Northern Africa
3    5270844           NA    Africa   Middle Africa
4      54681           NA  Americas       Caribbean
5   20619075 108322326649  Americas   South America
6    1867396           NA      Asia    Western Asia
gapminder_USA <- gapminder %>%       # creates US dataframe
  filter(country == "United States", year >= 1960 & year <= 2010)
gapminder_Vietnam <- gapminder %>%   # creates vietnam dataframe
  filter(country == "Vietnam", year >= 1960 & year <= 2010)
colors <- c("yellow", "steelblue", "black", "red", "orange", "blue" ) #color choices for points
highchart() |>
  hc_yAxis_multiples(
    list(title = list(text = "Life Expectancy (Years)")), #title for first y axis
    list(title = list(text = "Population (millions)" ), #title for second y axis
         opposite = TRUE)  ) |>
  hc_add_series(data = gapminder_USA$population,          #adds US-Population to chart
                name = "US-Population",
                type = "line",
                yAxis = 1) |>
  hc_add_series(data = gapminder_USA$life_expectancy,     #adds US-Life Expectancy to chart
                name = "US-Life Expectancy",
                type = "line",
                yAxis = 0) |>
  hc_add_series(data = gapminder_Vietnam$population,      #adds Vietnam-Population to chart
                name = "Vietnam-Population",
                type = "line",
                yAxis = 1) |>
  hc_add_series(data = gapminder_Vietnam$life_expectancy, #adds Vietnam-Life Expectancy to chart
                name = "Vietnam-Life Expectancy",
                type = "line",
                yAxis = 0) |>
  hc_xAxis(categories = gapminder_USA$year, # adds x-axis
           tickInterval = 5) |>
  hc_xAxis(title = list(text="Year")) |> # adds x-axis title
  hc_title(text = "Disparities in Health: The Decay of the Vietnamese and the Flourishing of the United States") |> # adds title
  hc_colors(colors) |> #adds colors
  hc_chart(style = list(fontFamily = "Georgia", # boldens and changes font to Georgia
                        fontWeight = "bold")) |>
  hc_legend(verticalAlign = "top", # places legend on top of chart and changes its orientation to horizontal
            layout = "horizontal") |>
  hc_add_annotations( # creates annotation on the year 1975 (did not work for whatever reason)
    list( labels = list( list(
            point = list(x = 1975, y = 60.54, xAxis = 0, yAxis = 0),
            text = "End of Vietnam War"
            )))) |>
  hc_add_theme(hc_theme_darkunica()) # changes theme to gray scale