Assignment 6 - Part 2

Author

Isaac Cuellar

Graph 1

library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.5.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── 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
nations <- read.csv("C:/Users/pc/Downloads/nations.csv")
nations <- nations %>% 
  mutate(gdp = gdp_percap * population / 1e12)
countries <- nations %>% 
  filter(country %in% c("China","Germany", "Japan", "United States"))
ggplot(countries,aes(x = year, y = gdp, color = country))+
  geom_line()+
  geom_point()+
  scale_color_brewer(palette="Set1")+
  labs(
    title = "China's Rise to Become the Largest Economy",
    x = "Year", y = "GDP($ trillion)")

Graph 2

regions <- nations %>% 
  group_by(region,year) %>% 
  summarise(gdp = sum(gdp,na.rm=TRUE))
`summarise()` has regrouped the output.
ℹ Summaries were computed grouped by region and year.
ℹ Output is grouped by region.
ℹ Use `summarise(.groups = "drop_last")` to silence this message.
ℹ Use `summarise(.by = c(region, year))` for per-operation grouping
  (`?dplyr::dplyr_by`) instead.
ggplot(regions,aes(x = year, y = gdp, fill = region))+
  geom_area(color = "black", size = 0.2)+
  scale_fill_brewer(palette = "Set2")+
  labs(
    title = "GDP by World Bank Region", x = "Year",
    y = "GDP ($ trillion)"
  )
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.