Nations GDP Charts

Author

Naomi Surendorj

library(dplyr)
library(ggplot2)
nations <- read.csv("nations_new.csv")
nations_four <- nations |>
  filter(country == "China" |
         country == "Germany" |
         country == "Japan" |
         country == "United States")

p1 <- nations_four |>
  ggplot(aes(x = year,
             y = (gdp_per_cap * population) / 1000000000000,
             color = country)) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1") +
  labs(
    x = "Year",
    y = "GDP (Trillions of Dollars)",
    title = "GDP Over Time for Selected Countries",
    caption = "Source: Nations Dataset"
  )

p1

nations_region <- nations |>
  group_by(region, year) |>
  summarise(GDP = sum((gdp_per_cap * population) / 1000000000000, na.rm = TRUE),
            .groups = "drop")
p2 <- nations_region |>
  ggplot(aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white", linewidth = 0.2) +
  scale_fill_brewer(palette = "Set2") +
  labs(
    x = "Year",
    y = "Total GDP (Trillions)",
    title = "Total GDP by Region Over Time",
    caption = "Source: Nations Dataset"
  )
p2