DATA 110 HW 5

Author

R.R.

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(ggplot2)
library(RColorBrewer)
nations <- read.csv("nations.csv")

Chart 1

nations_gdptril <- nations |>
  mutate(gpd_trillions = (gdp_percap * population) / 1e12)
selcon <- c("United States", "China", "Japan", "Germany")
nations_gpd_filtered <- nations_gdptril |>
  filter(country %in% selcon)
ggplot(nations_gpd_filtered, aes(year, gpd_trillions, 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 (Trillions of $)",
    color = "Country"
  ) +
  theme_minimal()

Chart 2

regions_sum <- nations_gdptril |>
    group_by(region, year) |>
    summarize(GDP = sum(gpd_trillions, na.rm = TRUE), .groups = "drop") 
ggplot(regions_sum, aes(x = year, y = GDP, fill = region)) +
    geom_area(color = "white", linewidth = 0.05) +
    scale_fill_brewer(palette = "Set2") +
    labs(
        title = "GDP by World Bank Region",
        x = "Year",
        y = "GDP ($ trillion)",
        fill = "region"
    )+
  theme_minimal()