Nations Charts

Author

Alex Lopez

Set-Up

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(ggplot2)
Warning: package 'ggplot2' was built under R version 4.3.3
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ lubridate 1.9.3     ✔ tibble    3.2.1
✔ purrr     1.0.2     ✔ tidyr     1.3.1
✔ readr     2.1.5     
── 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("/Applications/DATA110")
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

nations_new1 <- nations %>%
  mutate(gdp_tril = (gdp_percap * population)/1000000000000) %>%
  filter(country %in% c("China", "Germany", "Japan", "United States")) %>%
  filter(year >= 1990 & year < 2015)
ggplot(nations_new1, aes(x = year, y = gdp_tril, color = country)) + 
  geom_line() +
  labs(title = "China's Rise to Become the Largest Economy",
    x = "year",
    y = "GDP ($ trillion)") +
    scale_color_brewer(palette = "Set1") +
    geom_point(size = 1.25) +
  theme_minimal() 

Chart 2

nations_new2 <- nations %>%
  mutate(gdp_tril = (gdp_percap * population)/1000000000000) %>%
  filter(year >= 1990 & year < 2015) %>%
  group_by(region, year) %>%
  summarise(GDP = sum(gdp_tril, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
ggplot(nations_new2, aes(x = year, y = GDP, fill = region)) + 
  geom_area(color = "white") +
  labs(title = "GDP by World Bank Region",
    x = "year",
    y = "GDP ($ trillion)") +
    scale_fill_brewer(palette = "Set2") +
  theme_minimal()