NNguyen_NationsCharts

Chart 1

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   3.5.0     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── 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(ggplot2)
library(RColorBrewer)
library(plotly)

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout
getwd()
[1] "/Users/natty/Downloads/DATA110"
setwd("/Users/natty/Downloads/DATA110")
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.
largestFour <- nations |>
  mutate(gdp = gdp_percap * population / 10^12) |>
  filter(country == "China" | country == "Germany" | country == "Japan"| country == "United States")
chart1 <- largestFour |>
ggplot(aes(x = year, y = gdp, color = country)) +
scale_color_brewer(palette = "Set1") +
ylab("GDP ($ trillion)") +
theme_minimal(base_size = 12) +
geom_point() +
geom_line() +
xlim(1990,2014) +
ggtitle("China's Rise to Become the Largest Economy")
chart1

Chart 2

nations_area <- nations |>
  mutate(gdp = gdp_percap * population / 10^12) |>
  group_by(region, year) |>
  summarise(sum = sum(gdp, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
chart2 <- nations_area |>
ggplot(aes(x = year, y = sum, fill = region)) +
scale_fill_brewer(palette = "Set2") +
ylab("GDP ($ trillion)") +
theme_minimal(base_size = 12) +
geom_area(color = "white") +
ggtitle("GDP by World Bank Region")
chart2