Nations Charts HW

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.1     ✔ stringr   1.5.2
✔ 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)
setwd("C:/Users/ronnk/OneDrive/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.
# create country_gdp and divide by one trillion
nations <- nations %>%
  mutate(country_gdp = (gdp_percap * population/1e12))

First Chart

# filter the data to four countries
filtered_nations <- nations %>%
  filter(country %in% c("United States", "Philippines", "Thailand", "Indonesia"))
ggplot(filtered_nations, aes(x = year, y = country_gdp, color = country)) +
  geom_point(size = 2.5) +
  geom_line(size = 1.1) +
  scale_color_brewer(palette = "Set1") +
  labs(title = "Asian Countries' GDP Compared to the United States",
       x = "Years",
       y = "GDP(Trillions of $)")
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.

Second Chart

# group countries by region
regions_grouped <- nations %>%
  group_by(region, year) %>% 
  summarise(GDP = sum(gdp_percap, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
ggplot(regions_grouped, aes(x = year, y = GDP/1e12, fill = region)) +
  geom_area(color = "white", size = 0.2) +
  scale_fill_brewer(palette = "Set2") +
  labs(title = "GDP by World Bank Region",
       x = "Year",
       y = "GDP(Trillions of $)")