setwd("~/Desktop/RWD")
nations <- read.csv("nations.csv")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.0 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.1 ✔ tibble 3.1.8
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
nations <- mutate(nations, gdp = gdp_percap * population / 10^12)
filter_nations <- nations %>%
filter(country %in% c("Japan", "Germany", "China", "United States"))
ggplot(filter_nations, aes(x = year, y = gdp, color = country)) +
geom_point() +
geom_line() +
scale_color_brewer(palette = "Set1") +
ggtitle("China's Rise To Becoming The Biggest Economy") +
xlab("Year") +
ylab("GDP (trillions of dollars)")

nations2 <- 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.
ggplot(nations2, aes(x = year, y = gdp, fill = region)) +
geom_area (color = "white", linewidth = 0.2) +
scale_fill_brewer(palette = "Set2") +
ggtitle("GDP by World Bank Region") +
xlab("Year") +
ylab("GDP (trillions of dollars")
