Nations Assignment

# Load  libraries
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.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(RColorBrewer)

# Load the data 
nations <- read_csv("nations_new.csv")
Rows: 13184 Columns: 9
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (4): country, iso3c, region, wb_income
dbl (5): year, birth_rate, neonatal_death_rate, population, gdp_per_cap

ℹ 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_per_cap * population) / 10^12)
# Filter for the four specific countries
nations_filtered <- nations %>%
  filter(country %in% c("China", "Germany", "Japan", "United States"))

# Draw the line and point chart
ggplot(nations_filtered, aes(x = year, y = gdp, color = country)) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1") +
  labs(title = "GDP Growth of Selected Nations",
       y = "GDP ($ trillion)",
       x = "Year",
       color = "Country") +
  theme_minimal()

# Group by region and year, then summarize
nations_regions <- nations %>%
  group_by(region, year) %>%
  summarise(GDP = sum(gdp, na.rm = TRUE), .groups = 'drop')

# Draw the area chart
# 
ggplot(nations_regions, aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white", linewidth = 0.2) +
  scale_fill_brewer(palette = "Set2") +
  labs(title = "Total GDP by World Bank Region",
       y = "GDP ($ trillion)",
       x = "Year",
       fill = "Region") +
  theme_minimal()

nrow(filter(nations, country == "China"))
[1] 0

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1 + 1
[1] 2

You can add options to executable code like this

[1] 4

The echo: false option disables the printing of code (only output is displayed).