# I loaded the libraries and installed my dataset here as a csv
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.5.2
## Warning: package 'ggplot2' was built under R version 4.5.2
## Warning: package 'dplyr' was built under R version 4.5.2
## Warning: package 'forcats' was built under R version 4.5.2
## Warning: package 'lubridate' was built under R version 4.5.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.0 ✔ readr 2.1.5
## ✔ forcats 1.0.1 ✔ stringr 1.5.1
## ✔ ggplot2 4.0.2 ✔ tibble 3.3.0
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── 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
nations_Copy <- read_csv("nations - Copy.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.
# In this chunk I created a new variable for GDP in trillions to make it easier to compare countries. I made two charts: one comparing a few countries, and one showing GDP by region. My goal is to see how different countries and regions have grown economically over the years.
nations <- nations_Copy %>%
mutate(gdp = (gdp_percap * population) / 1e12)
#In this chunk I picked 4 countries to focus on and made a chart showing how their GDP changes over time. I used lines to show trends and points for actual values so it’s easier to see the differences.
countries_data <- nations %>%
filter(country %in% c("United States", "China", "India", "Japan"))
# Plot GDP over time
ggplot(countries_data, aes(x = year, y = gdp, color = country)) +
geom_line() +
geom_point() +
scale_color_brewer(palette = "Set1") +
labs(
title = "GDP Growth of Selected Countries",
x = "Year",
y = "GDP (Trillions USD)"
) +
theme_minimal()

# In this chunk I grouped the data by region and added up the GDP to see total economic growth by region. The area chart shows how each region contributes to global GDP over time.
region_data <- nations %>%
group_by(region,year) %>%
summarise(GDP = sum(gdp,na.rm = TRUE))
## `summarise()` has regrouped the output.
## ℹ Summaries were computed grouped by region and year.
## ℹ Output is grouped by region.
## ℹ Use `summarise(.groups = "drop_last")` to silence this message.
## ℹ Use `summarise(.by = c(region, year))` for per-operation grouping
## (`?dplyr::dplyr_by`) instead.
ggplot(region_data, aes(x = year, y = GDP, fill = region)) +
geom_area(color = "white", size = 0.2) +
scale_fill_brewer(palette = "Set2") +
labs(
title = "Total GDP by Region Over Time",
x = "Year",
y = "GDP (Trillions USD)"
) +
theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
