nationsHomework

Author

Dekker Spielman

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.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ 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
setwd("~/aaaworkingdirectory")
nations <- read_csv("nations.csv") |>
  mutate(gdptril = gdp_percap * population / 1000000000000)
Rows: 5275 Columns: 10
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): iso2c, iso3c, country, region, income
dbl (5): year, gdp_percap, population, birth_rate, neonat_mortal_rate

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
nationG1 <- nations |>
  filter(country %in% c("China", "Germany", "Japan", "United States")) |>
  ggplot(aes(year, gdptril, color = country)) +
  scale_color_brewer(palette = "Set1")+
  geom_point()+
  geom_line()+
  labs(x = "Year",
       y = "GDP ($ Trillion)",
       title = "China's Rise to Become the Largest Economy",
       color = "")
nationG1

nationG2 <- nations |>
  group_by(year, region) |>
  summarise(sum_GDP = sum(gdptril, na.rm = TRUE)) |>
  ggplot(aes(year, sum_GDP, fill = region)) +
  scale_fill_brewer(palette = "Set2")+
  geom_area(color = "white")+
  labs(x = "Year",
       y = "GDP ($ Trillion)",
       title = "GDP by World Region",
       fill = "")
`summarise()` has grouped output by 'year'. You can override using the
`.groups` argument.
nationG2