Nations Dataset Charts

library(dplyr)
library(ggplot2)

nations <- read.csv("~/Downloads/nations.csv")
nations <- nations |>
  mutate(gdp = gdp_percap * population / 1e12)
four_countries <- nations |>
  filter(country %in% c("China", "United States", "Japan", "Germany"))
ggplot(four_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)",
    color = "country"
  ) +
  theme_minimal()

region_gdp <- nations |>
  group_by(region, year) |>
  summarise(GDP = sum(gdp, na.rm = TRUE), .groups = "drop")
ggplot(region_gdp, 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)",
    fill = "region"
  ) +
  theme_minimal()