Assignment 6 Part 2 Nations Charts

Author

Rin Hwang

nation.csv is a dataset that provides each country’s GDP, year, population, birth rate, neonatal mortality rate, region, and level of income.

Uploading the dataset

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
setwd("C:/Users/hwang/OneDrive/Documents/MC stuff/Spring 2026/DATA 110 Data Visualization and Communication/Assignments/Datasets")
nations <- read_csv("nations.csv")
Rows: 5275 Columns: 10
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): iso2c, iso3c, country, region, income
dbl (5): year, gdp_percap, population, birth_rate, neonat_mortal_rate

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Chart 1: Line Chart of China’s Economic Rise

nations <- nations %>%
  mutate(gdp_trillions = (gdp_percap * population) / 10^12)

countries_of_interest <- c("China", "Germany", "Japan", "United States")

linegraph <- nations %>%
  filter(country %in% countries_of_interest)

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

Chart 2: Stacked Chart of GDP by World Bank Region

stackedchart <- nations %>%
  group_by(region, year) %>%
  summarise(total_gdp = sum(gdp_trillions, na.rm = TRUE), .groups = "drop")

ggplot(stackedchart, aes(x = year, y = total_gdp, fill = region)) +
  geom_area(color = "white", linewidth = 0.2) + 
  scale_fill_brewer(palette = "Set2") +
  labs(title = "GDP by World Bank Region",
       y = "GDP ($ trillion)",
       x = "year",
       fill = "region") +
  theme_minimal()