Nations Assignment

Author

K-Bedassa

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.4     ✔ 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(ggfortify)
library(dplyr)
library(ggplot2)
library(ggalluvial)
getwd()
[1] "/Users/kidusteffera/Desktop/DATA110/Week 6 "
setwd("/Users/kidusteffera/Desktop/DATA110/Week 6 ")
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 <- 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.
gdp_summary <- nations |>
  group_by(region, year) |>
  summarize(GDP = sum(gdp_percap, 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.
nations_chart <- ggplot(nations, aes(x = year, y = gdp_percap/10^4)) +
 labs(title = "GDP of the Rarest Country I Have Traveled too",
      x = "year",
      y = "GDP ($ Trillion)") +
  theme_minimal(base_size = 12) 
 nations_chart

I selected this 4 countries because it was one of the best countries I travelled too

selected_countries <- nations |>
  filter(country %in% c("Uzbekistan", "Vietnam", "Latvia", "Hong Kong SAR, China"))

dot gragh

ggplot(selected_countries, aes(x = year, y = gdp_percap/10^3, color = country)) +
  geom_line() +
  geom_point() +
  ggtitle("GDP of the Rarest Country I Have Traveled too")
Warning: Removed 5 rows containing missing values or values outside the scale range
(`geom_line()`).
Warning: Removed 5 rows containing missing values or values outside the scale range
(`geom_point()`).

geom area graph

ggplot(gdp_summary, aes(x = year, y = GDP/10^5, fill = region)) +
  geom_area() +
  labs(
    title = "GDP by Region Over Time",
    x = "Year",
    y = "Total GDP"
  ) +
  theme_minimal()

GG Alluvium

ggalluv <- gdp_summary |>
  ggplot(aes(x = year, y = GDP/10^5, alluvium = region)) + 
  theme_bw() +
  geom_alluvium(aes(fill = region), 
                color = "white",
                width = .1, 
                alpha = .8,
                decreasing = FALSE) +
  scale_fill_brewer(palette = "Spectral") + 
  # Spectral has enough colors for all countries listed
  scale_x_continuous(lim = c(1990,2015)) +
  labs(title = "GDP by Region Over Time",
       x = "Year", 
       y = "Total GDP", 
       fill = "region",
       caption = "GDP by Region Over Time")
ggalluv