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(ggplot2)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ lubridate 1.9.5 ✔ tibble 3.3.1
## ✔ purrr 1.2.1 ✔ tidyr 1.3.2
## ✔ readr 2.1.6
## ── 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
setwd("/Users/precious/Downloads/DATASETS")
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 = (gdp_percap * population) / 1e12)
chart1_data <- nations %>%
filter(country %in% c("China", "Germany", "Japan", "United States"))
ggplot(chart1_data, aes(x = year, y = gdp, color = country)) +
geom_point() +
geom_line() +
scale_color_brewer(palette = "Set1") +
labs(
title = "China's Rise to the Largest Economy",
x = "year",
y = "GDP ($ trillion)",
color = NULL
) +
theme_minimal()

chart2_data <- nations %>%
group_by(region, year) %>%
summarize(GDP = sum(gdp, na.rm = TRUE), .groups = "drop")
ggplot(chart2_data, 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"
) +
theme_minimal()
