GDP_AREA

Author

Gamaliel Ngouafon

Load Libraries

library(tidyverse)

Go to Working Directory

getwd()
[1] "/Users/darrenabou/Desktop/Spring 26/Data110"

Read dataset into the Global Environment

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.
head(nations)
# A tibble: 6 × 10
  iso2c iso3c country  year gdp_percap population birth_rate neonat_mortal_rate
  <chr> <chr> <chr>   <dbl>      <dbl>      <dbl>      <dbl>              <dbl>
1 AD    AND   Andorra  1996         NA      64291       10.9                2.8
2 AD    AND   Andorra  1994         NA      62707       10.9                3.2
3 AD    AND   Andorra  2003         NA      74783       10.3                2  
4 AD    AND   Andorra  1990         NA      54511       11.9                4.3
5 AD    AND   Andorra  2009         NA      85474        9.9                1.7
6 AD    AND   Andorra  2011         NA      82326       NA                  1.6
# ℹ 2 more variables: region <chr>, income <chr>

Cleaning datasets by removing all NA’s values

nations_clean<- nations|>
  filter(! is.na(gdp_percap) & !is.na(population) & !is.na(birth_rate) & !is.na(neonat_mortal_rate) & !is.na(region) & !is.na(income) & !is.na(iso2c) & !is.na(iso3c) & !is.na(country) &!is.na(year))
nations_clean
# A tibble: 4,303 × 10
   iso2c iso3c country  year gdp_percap population birth_rate neonat_mortal_rate
   <chr> <chr> <chr>   <dbl>      <dbl>      <dbl>      <dbl>              <dbl>
 1 AE    ARE   United…  1991     73037.    1913190       24.6                7.9
 2 AE    ARE   United…  1993     71960.    2127863       22.4                7.3
 3 AE    ARE   United…  2001     83534.    3217865       15.8                5.5
 4 AE    ARE   United…  1992     73154.    2019014       23.5                7.6
 5 AE    ARE   United…  1994     74684.    2238281       21.3                6.9
 6 AE    ARE   United…  2007     75427.    6010100       12.8                4.7
 7 AE    ARE   United…  2004     87844.    3975945       14.2                5.1
 8 AE    ARE   United…  1996     79480.    2467726       19.3                6.4
 9 AE    ARE   United…  2006     82754.    5171255       13.3                4.9
10 AE    ARE   United…  2000     84975.    3050128       16.4                5.6
# ℹ 4,293 more rows
# ℹ 2 more variables: region <chr>, income <chr>

Creating a new variable consisting of calculated GDP

GDP_Summary <- nations_clean |>
  mutate(GDP = (gdp_percap*population)/10^12) |>
  group_by(region, year) |>
  summarise(GDP = sum(GDP, na.rm = TRUE)) |>
         arrange(desc(GDP))
`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.
GDP_Summary
# A tibble: 175 × 3
# Groups:   region [7]
   region                 year   GDP
   <chr>                 <dbl> <dbl>
 1 East Asia & Pacific    2014  32.0
 2 East Asia & Pacific    2013  30.1
 3 East Asia & Pacific    2012  28.1
 4 Europe & Central Asia  2014  26.5
 5 East Asia & Pacific    2011  26.0
 6 Europe & Central Asia  2013  25.8
 7 Europe & Central Asia  2012  25.2
 8 Europe & Central Asia  2011  24.5
 9 East Asia & Pacific    2010  24.0
10 Europe & Central Asia  2010  23.0
# ℹ 165 more rows

Area plot for region

library(RColorBrewer)
GDP_Area<- ggplot(GDP_Summary, aes(x= year, y = GDP, fill = region))+
  geom_area( alpha = 0.9)+
  scale_fill_brewer(palette = "Set2")+
  labs(
    title = "GDP by WorldBnak Region",
    x= "year",
    y= "GDP ($trillion)",
    color = "region"
  )+
  theme_minimal()
GDP_Area
Ignoring unknown labels:
• colour : "region"

Alluvial plot for Area (Extra Credit)

library(alluvial)
library(ggalluvial)
Warning: package 'ggalluvial' was built under R version 4.5.2
library(RColorBrewer)
GDP_alluv <- ggplot(GDP_Summary, aes(x = year, y = GDP, alluvium = region))+
  geom_alluvium(aes(fill = region), 
                width = .1, 
                alpha = .8,
                decreasing = FALSE) + 
  scale_fill_brewer(palette = "Set2")+
  labs(
    title = "GDP by WorldBnak Region",
    x= "year",
    y= "GDP ($trillion)",
    color = "region"
  )+
  theme_minimal()
GDP_alluv
Ignoring unknown labels:
• colour : "region"

Between 1990 and 2015, the world economy underwent one of the most dramatic global transformations in modern history.These two visualizations, both charting GDP across World Bank regions, tell that story, but each subtly in different ways.

The first chart, a stacked area plot, tells a cleaner, more cumulative version of the same story. Here the world’s total GDP exponentially grew from roughly $25 trillion 1990 and over 4 100 trillion in 2015. East Asia & Pacific for example, stands out the most dramatically, for keeping the same consistency in their development. The graph show how they have been leading for more than 25 years. While Sub-saharan and South Asia though growing, remains visibly thin at the bottom.

The second chart, an alluvial plot, is more descriptive and captures the noise beneath the surface. the overlapping areas demonstrates periods where certain regions experienced favourable economic conditions compared to the other ones. in the decade of 2000- 2010, we can observe that the Global Financial Crisis left a visible scar on the chart, particularly in Europe & Central, before recovering from it in the following decade