Week6- Nations

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.3     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.3     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ 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
Nations <-read_csv("nations.csv", show_col_types = FALSE)
Nations <- Nations |> 
  mutate(gdp_trillions = gdp_percap * population / 1e12)
countrys <- Nations |>
  filter(country %in% c("China", "Italy", "Zimbabwe", "United States"))
 #=="China" | country == "Italy" |country == "Zimbabwe" | country == "United States")

ggplot(countrys, aes(x= year, y=gdp_trillions, color= country))+
  geom_point()+
  geom_line()+
  scale_color_brewer(palette = "Set1")+
  labs(x= "Year", y = "GDP ($Trillions)", title = "Worlds Apart")

regions <- countrys |>
  group_by(region , year) |>
summarise( countrys = sum(gdp_trillions, na.rm = TRUE), .groups = 'drop')
ggplot(countrys, aes(x=year, y= gdp_trillions, fill = region )) +
  geom_area( color= "white", size= .25)+
  scale_fill_brewer(palette = "Set2")+
  labs(y= "GDP ($Trillions)" , x= "Year", title = "GDP by World Bank")
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.