library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.4.1 
## ✔ readr   2.1.2      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(dplyr)
library(RColorBrewer)
library(ggplot2)

Read in dataset

setwd("/Users/KathyOchoa/Documents/DATA 110/CSV Files")
nationsData <- 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.

Create a new variable, GDP of each country, using mutate

oneTrillion = 1*(10^12)
nationsData <- nationsData %>%
  mutate(gdp = (gdp_percap * population) / oneTrillion)

First Chart

chart1data <- nationsData %>%
  group_by(country) %>%
  filter(country == 'United Arab Emirates' | country == 'Singapore' | country == 'Switzerland' | country == 'Hong Kong SAR, China')

chart1 <- ggplot(chart1data, aes(x=year, y = gdp, fill = country, color = country)) +
  labs(title = "GDP in Countries with the Highest % of Expats", caption = "Source: Expatrace.com") +
  geom_line() +
  xlab("Year") +
  ylab("GDP ($ trillion)") + 
  geom_point() +
  scale_color_brewer(palette = "Set1") +
  theme_minimal(base_size = 14)

chart1

Second Chart

chart2data <- nationsData %>%
  group_by(region, year) %>%
  summarise(GDP = sum(gdp, na.rm = TRUE))
## `summarise()` has grouped output by 'region'. You can override using the
## `.groups` argument.
chart2 <- ggplot(chart2data, aes(x=year, y = GDP, fill = region)) +
  geom_line() +
  geom_area(color = "white") +
  xlab("Year") +
  ylab("GDP ($ trillion)") +
  scale_fill_brewer(palette = "Set2") +
  labs(title = "GDP by World Bank Region") +
  theme_minimal(base_size = 12)

chart2