HW 6 Data 110

ggplot Graph:

library(ggplot2)
Warning: package 'ggplot2' was built under R version 4.4.2
library(tidyverse)
Warning: package 'purrr' was built under R version 4.4.3
Warning: package 'lubridate' was built under R version 4.4.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ lubridate 1.9.4     ✔ tibble    3.2.1
✔ purrr     1.0.4     ✔ tidyr     1.3.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
library(dplyr)
library(highcharter)
Warning: package 'highcharter' was built under R version 4.4.3
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
nations <- read.csv("L:/R_Datasets/nations(1).csv") |>
  mutate(gdp_tn = gdp_percap*population/10^12)

big4 <- nations |>
  filter(iso3c %in% c("CHN","DEU", "JPN", "USA")) |>
  arrange(year)
ggplot(big4, aes(x = year, y = gdp_tn, color = country,  group = country)) +
  geom_line() +
  geom_point() +
  scale_color_brewer(palette = "Set1") +
  labs(x = "Year", y = "GDP ($ trillion)", color = "Country") +
  theme_minimal() +
  theme(legend.position = "top", legend.justification = "right")

Interactive Graph:

# prepare data
regions <- nations |>
  group_by(year,region) |>
  summarize(gdp_tn = sum(gdp_tn, na.rm = TRUE)) |>
  arrange(year,region)
`summarise()` has grouped output by 'year'. You can override using the
`.groups` argument.

ggplot Graph:

ggplot(regions, aes(x = year, y = gdp_tn, fill = region)) +
  geom_area() +
  scale_fill_brewer(palette = "Set2") +
  labs(x = "Year", y = "GDP ($ trillion)", fill = "Region", title = "GDP by World Bank Region") +
  theme_minimal() +
  theme(legend.justification = "right")