Nations Assignment

Author

Tj

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.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── 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(RColorBrewer)
setwd("/Users/thejitharajapakshe/Desktop/DATA 110")
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.
nations_nona <- nations |>
  filter(!is.na(gdp_percap) & !is.na(birth_rate))  

nationsw_gdp <- nations_nona |> 
  mutate(GDP = (gdp_percap * population)/10^12)

First Chart

mycountries <- c("Oman", "United Arab Emirates", "Saudi Arabia", "Kuwait")
country4 <- nationsw_gdp |>
  filter(country %in% mycountries)

ggplot(country4, aes(x = year, y = GDP, color = country)) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1") +
  labs(x = "Year", y = "GDP ($trillion)", title = "The Big 4 of the Middle East") +
  theme_minimal()

Second Chart

gdp_perregion <- nationsw_gdp %>%
  group_by(region, year) %>%
  summarize(sum_GDP = sum(GDP, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
ggplot(gdp_perregion, aes(x = year, y = sum_GDP, fill = region)) +
  geom_area(color = "white",size = 0.2) +
  scale_fill_brewer(palette = "Set2") +
  labs(x = "Year", y = "GDP (Trillions of dollars)", title = "GDP by World Bank Region") +
  theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.