Nations Charts Assignment

library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.5.3
Warning: package 'ggplot2' was built under R version 4.5.3
Warning: package 'tidyr' was built under R version 4.5.3
Warning: package 'readr' was built under R version 4.5.3
Warning: package 'purrr' was built under R version 4.5.3
Warning: package 'stringr' was built under R version 4.5.3
Warning: package 'forcats' was built under R version 4.5.3
Warning: package 'lubridate' was built under R version 4.5.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.2.0
✔ 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
library(RColorBrewer)
nations <- read_csv("nations.csv")
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.
nations <- nations %>%
  mutate(gdp = gdp_percap * population / 1000000000000)

Chart 1

chart1_data <- nations %>%
  filter(country %in% c("China","Germany","Japan","United States"))

ggplot(chart1_data, aes(x = year, y = gdp, color = country)) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1") +
  labs(
    title = "China's Rise to Become the Largest Economy",
    x = "year",
    y = "GDP ($ trillion)"
  ) +
  theme_minimal()

Chart 2

chart2_data <- nations %>%
  group_by(region, year) %>%
  summarise(GDP = sum(gdp, na.rm = TRUE), .groups = "drop")

ggplot(chart2_data, aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white", linewidth = 0.2) +
  scale_fill_brewer(palette = "Set2") +
  labs(
    title = "GDP by World Bank Region",
    x = "year",
    y = "GDP ($ trillion)"
  ) +
  theme_minimal()