Nations Charts Assignments

Author

Micaela T

Load the Libraries

library(tidyverse)
setwd("~/Data 110")
nations <- read.csv("nations.csv")
library(dplyr)
library(ggplot2)
library(RColorBrewer)

Plot 1: Comparision of Latin America & Caribbean GDP Over Time

nations <- nations %>%
  mutate(gdp = gdp_percap  * population / 10^12)
countries <- c("Mexico", "Puerto Rico", "Brazil", "Peru")

nations_countries <- nations %>%
  filter(country %in% countries)
  latin_america_caribbean <- nations %>%
  filter(region == "Latin America & Caribbean")

ggplot(nations_countries, aes(x = year, y = gdp, color = country)) +
  geom_line(size = 1) +
  geom_point(size = 2) +
  scale_color_brewer(palette = "Set1") +
  labs(
    title = "Comparision of Latin America & Caribbean GDP Over Time",
    x = "Year",
    y = "GDP ($ trillion)") +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 14, face = "bold"),
    legend.title = element_blank()
 ) 

Plot 2: GDP by World Bank Region

# Group data by region and year, then calculate total GDP
nations_region <- nations %>%
  group_by(region, year) %>%
  summarise(GDP = sum(gdp, na.rm = TRUE))

# Plot total GDP by region over time
ggplot(nations_region, aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white") + 
  scale_fill_brewer(palette = "Set2") + 
  labs(
    title = "GDP by World Bank Region", 
    x = "Year",
    y = "GDP (trillions)"
  ) + 
  theme_minimal()