Nations HW

Author

J Amaya

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   4.0.0     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── 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)
library(ggplot2)
setwd("~/Desktop/Desktop - Jackie’s MacBook Pro/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.

Mutate GDP by trillion

nations <- nations |>
  mutate(gdp = (gdp_percap * population) / (10e12))

Filter by four countries I want to visit

nations_latin <- nations |>
  filter(country %in% c("Brazil", "Costa Rica", "Chile", "Colombia"))

Design the graph

latin_chart <-
  ggplot(nations_latin, aes(x = year,
                                        y = gdp,
                                        color = country)) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1") + 
  labs(title = "Brazil's Dominance in GDP Over Time",
       x = "Year",
       y = "GDP (in Trillions)",
       caption = "Source: Nations Dataset")
latin_chart

Filter by region

nations_region <- nations |>
  group_by(region, year) |>
  summarise(gdp = sum(gdp, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.

Design the region chart

region_chart <- nations_region |>
  ggplot(aes(x = year,
             y = gdp,
             fill = region)) +
  geom_area(color = "white",) +
  labs(title = "Total GDP by Region",
    x = "Year",
    y = "GDP (in Trillions)",
    caption = "Source = Nations Dataset") +
  scale_fill_brewer(palette = "Set2")
region_chart