Nations Charts

Author

NCowan

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.2     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── 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
library(ggplot2)
library(dplyr)
nations <- read.csv("nations.csv")
nations <- nations %>%
  mutate(gdp = (gdp_percap * population) / 1e12)
my_countries <- c("United Arab Emirates", "Saudi Arabia", "Oman", "Yemen, Rep.")
nations_filtered <- nations %>%
  filter(country %in% my_countries)

ggplot(nations_filtered, aes(x = year, y = gdp, color = country)) +
  geom_line(size = 1) +
  geom_point(size = 2) +
  scale_color_brewer(palette = "Set1") +
  labs(
    title = "GDP Over Time",
    x = "Year",
    y = "GDP ($ Trillion)",
    color = "Country"
  ) +
  theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_line()`).
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_point()`).

region_gdp <- nations %>%
  group_by(region, year) %>%
  summarise(GDP = sum(gdp, na.rm = TRUE)) %>%
  ungroup()
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
ggplot(region_gdp, aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white", size = 0.1) +
  scale_fill_brewer(palette = "Set2") +
  labs(
    title = "GDP by World Bank Region",
    x = "Year",
    y = "Total GDP ($ Trillion)",
    fill = "Region"
  ) +
  theme_minimal()