ACTIVITY9

Author

Christopher Hamatto

library(readr)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(readr)
library(ggplot2)

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 <- nations |>
  mutate(gdp_tn = gdp_percap * population / 10^12)
big4 <- nations |>
  filter(iso3c %in% c("CHN", "DEU", "JPN", "USA"))

ggplot(big4, aes(x = year, y = gdp_tn,
                 color = country, group = country)) +
  geom_line() +
  geom_point() +
  scale_color_brewer(palette = "Set1") +
  labs(
    title = "China's Rise to Become the Largest Economy",
    x = "year",
    y = "GDP ($ trillion)",
    color = NULL
  )

region_gdp <- nations |>
  group_by(region, year) |>
  summarise(gdp = sum(gdp_tn, na.rm = TRUE))
`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.
ggplot(region_gdp, aes(x = year, y = gdp, fill = region)) +
  geom_area(color = "white", linewidth = 0.2) +
  scale_fill_brewer(palette = "Set2") +
  labs(
    title = "GDP by World Bank Region",
    x = "year",
    y = "GDP ($ trillion)",
    fill = "region"
  )

ggplot(region_gdp, aes(x = year, y = gdp, fill = region)) +
  geom_area(color = "white", linewidth = 0.2) +
  scale_fill_brewer(palette = "Set2") +
  labs(
    title = "GDP by World Bank Region",
    x = "year",
    y = "GDP ($ trillion)",
    fill = "region"
  )

big4 <- nations |>
  filter(iso3c %in% c("CHN", "DEU", "JPN", "USA"))

ggplot(big4, aes(x = year, y = gdp_tn, color = country)) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1") +
  labs(
    title = "China's Rise to Become the Largest Economy",
    x = "year",
    y = "GDP ($ trillion)"
  )