Nations Assignment

Author

Jean Tcheby

Nations Dataset Charts

This assignment uses the Nations dataset to create two charts using dplyr and ggplot2.

library(tidyverse)
library(readr)
# Load dataset (file must be in Documents and named EXACTLY nations.csv)
nations <- read_csv("nations.csv")
# Create GDP variable in trillions
nations <- nations %>%
  mutate(GDP = (gdp_percap * population) / 1e12)

Chart 1: China’s Rise to Become the Largest Economy

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

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

Chart 2: GDP by World Bank Region

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() +
  labs(
    title = "GDP by World Bank Region",
    x = "Year",
    y = "GDP ($ trillion)",
    fill = "Region"
  ) +
  scale_fill_brewer(palette = "Set2") +
  theme_minimal()