Assignment 6 - Part 2

Author

Wesley Samimi

Load Libraries & Data

library(tidyverse)
library(dplyr)
library(ggplot2)
setwd("C:/Users/wesle/Downloads/Data 110")
nations <- read_csv("nations.csv")

Mutate GDP

nations1 <- nations |>
  mutate(gdp = (gdp_percap*population)/1000000000000)

Filter for Four Countries

nations2 <- nations1 |>
  filter(country %in% c("China", "Japan", "Germany", "United States"))

Plot 1

nations2 |>
  ggplot(aes(x = year, y = gdp, fill = country, color = country)) +
  geom_point() +
  geom_line() +
  ylab("GDP (In Trillions)") +
  scale_color_brewer(palette = "Set1")

Group By & Summarize

nations3 <- nations1 |>
  group_by(region, year) |>
  summarise(GDP = sum(gdp, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.

Plot 2

nations3 |>
  ggplot(aes(x = year, y = GDP, fill = region, color = region)) +
  geom_area(color = "white") +
  ylab("GDP (In Trillions)") +
  scale_fill_brewer(palette = "Set2")