Nations Charts Assignments

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── 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
nations <- read.csv("/Users/eabban/College Stuff/R Studio/nations.csv")

Cleaning N/A

nations_clean <- nations |>
  filter(!is.na(gdp_percap) & !is.na(population))

GDP

gdp_nations <- nations_clean  |>
  mutate(gdp = (gdp_percap * population)/10^12)

Plot #1

gdp_nations |>
  filter(country %in% c("Ghana", "South Africa", "Sudan", "Nigeria")) |>
  ggplot(aes(x = year, y = gdp, color = country)) +
  geom_line() +
  geom_point() +
  scale_color_brewer(palette = "Set1") +
  xlab ('Year') +
  ylab('GDP($trillion)') +
  labs (title = "Nigeria Rises to Become the Largest Economy")

Plot #2

gdp_nations |>
  group_by(region, year) |>
  summarise(GDP = sum(gdp, na.rm = TRUE)) |>
  ggplot(aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white", linewidth = 0.2) +
  scale_fill_brewer(palette = "Set2") +
  xlab("Year") +
  ylab ("GDP ($trillion)")+
  labs (title = "GDP by World Bank Region")
`summarise()` has regrouped the output.
ℹ Summaries were computed grouped by region and year.
ℹ Output is grouped by region.
ℹ Use `summarise(.groups = "drop_last")` to silence this message.
ℹ Use `summarise(.by = c(region, year))` for per-operation grouping
  (`?dplyr::dplyr_by`) instead.