Nations Charts

Load libraries and datasets

library(tidyverse)
nations <- read.csv("nations.csv")
head(nations)
  iso2c iso3c country year gdp_percap population birth_rate neonat_mortal_rate
1    AD   AND Andorra 1996         NA      64291       10.9                2.8
2    AD   AND Andorra 1994         NA      62707       10.9                3.2
3    AD   AND Andorra 2003         NA      74783       10.3                2.0
4    AD   AND Andorra 1990         NA      54511       11.9                4.3
5    AD   AND Andorra 2009         NA      85474        9.9                1.7
6    AD   AND Andorra 2011         NA      82326         NA                1.6
                 region      income
1 Europe & Central Asia High income
2 Europe & Central Asia High income
3 Europe & Central Asia High income
4 Europe & Central Asia High income
5 Europe & Central Asia High income
6 Europe & Central Asia High income

Plot 1

nations <- nations |>
  mutate(gdp = (gdp_percap * population) / 1000000000000)
nations_4 <- nations |>
  filter(country %in% c("China", "Germany", "United States", "Japan"))
ggplot(nations_4, aes(x = year, y = gdp, colour = country)) +
  geom_line() +
  geom_point() +
  scale_color_brewer(palette = "Set1", name = "") + 
  labs(x = "Year", y = "GDP ($ trillion)", title = "China's Rise to Become the Largest Economy") +
  theme_minimal()

Plot 2

nations2 <- nations |>
  group_by(region, year) |>
  summarise(gdp = sum(gdp, na.rm = TRUE))
ggplot(nations2, aes(x = year, y = gdp, fill = region)) +
  geom_area(color = "white") +
  scale_fill_brewer(palette = "Set2", name = "Region") +
  labs(x="Year", y = "GDP ($ trillion)", title = "GDP by World Bank Region") +
  theme_minimal()