Nations Dataset Charts

Author

Zyam Jadoon Khawaja

Published

May 15, 2026

Setup

Code
setwd("C:/Users/zyamj/Downloads")

# Load required libraries
library(tidyverse)

# Load dataset using readr::read_csv()
nations <- readr::read_csv("nations.csv")

# Preview the data
glimpse(nations)
Rows: 5,275
Columns: 10
$ iso2c              <chr> "AD", "AD", "AD", "AD", "AD", "AD", "AD", "AD", "AD…
$ iso3c              <chr> "AND", "AND", "AND", "AND", "AND", "AND", "AND", "A…
$ country            <chr> "Andorra", "Andorra", "Andorra", "Andorra", "Andorr…
$ year               <dbl> 1996, 1994, 2003, 1990, 2009, 2011, 2004, 2010, 200…
$ gdp_percap         <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ population         <dbl> 64291, 62707, 74783, 54511, 85474, 82326, 78337, 84…
$ birth_rate         <dbl> 10.900, 10.900, 10.300, 11.900, 9.900, NA, 10.900, …
$ neonat_mortal_rate <dbl> 2.8, 3.2, 2.0, 4.3, 1.7, 1.6, 2.0, 1.7, 2.1, 2.1, 2…
$ region             <chr> "Europe & Central Asia", "Europe & Central Asia", "…
$ income             <chr> "High income", "High income", "High income", "High …

Create GDP Variable

Code
# Use mutate to create a new variable: GDP in trillions of dollars
# GDP = gdp_percap * population / 1,000,000,000,000
nations <- nations %>%
  mutate(gdp = (gdp_percap * population) / 1e12)

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

Code
# Filter for the four countries of interest
nations %>%
  filter(country %in% c("China", "Germany", "Japan", "United States")) %>%
  ggplot(aes(x = year, y = gdp, color = country)) +
  geom_line(linewidth = 1.2) +
  geom_point(size = 2) +
  scale_color_brewer(palette = "Set1") +
  labs(
    title    = "China's Rise to Become the Largest Economy",
    x        = "Year",
    y        = "GDP ($ trillions)",
    color    = "Country",
    caption  = "Data source: World Bank via nations.csv"
  ) +
  theme_minimal(base_size = 13) +
  theme(
    plot.title      = element_text(face = "bold"),
    legend.position = "right",
    panel.grid.minor = element_blank()
  )


Chart 2: GDP by World Bank Region

Code
# Group by region and year, then summarize GDP
nations %>%
  group_by(region, year) %>%
  summarise(GDP = sum(gdp, na.rm = TRUE), .groups = "drop") %>%
  ggplot(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 ($ trillions)",
    fill    = "Region",
    caption = "Data source: World Bank via nations.csv"
  ) +
  theme_minimal(base_size = 13) +
  theme(
    plot.title       = element_text(face = "bold"),
    legend.position  = "right",
    panel.grid.minor = element_blank()
  )