GDP Assignment

Author

Dormowa Sherman

Published

October 10, 2023

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.3     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.3     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ 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(dplyr)
nat <- read.csv("nations.csv")
nat1 <- mutate(nat, GDP = (gdp_percap * population/10^9))
nat2 <- filter(nat1, country == "Nigeria" | country == "Egypt, Arab Rep." | country == "South Africa" | country == "Algeria")
ggplot (nat2, aes(x = year, y = GDP, color = country)) +
  labs(x = "Year", y = "GDP ($billion)", title = "Africa's Largest Economies") +
  theme_minimal() +
  geom_point() +
  geom_line() +
  scale_color_brewer(name = "", palette = 'Set1')

nat3 <- nat1 |>
  group_by(region, year) |>
  summarise(GDP = sum(GDP, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
ggplot(nat3, aes(x = year, y = GDP, fill = region)) +
  theme_minimal() +
  labs(x = "Year", y = "GDP ($trillion)", title = "GDP by World Bank Region") +
  geom_area(color = "white") +
  scale_fill_brewer(palette = "Set2")