Presenting GDP of each country in trillions of dollars

nations_mutate<- mutate(nations, gdp_trillion = (gdp_percap*population)/(10^12))
tail(nations_mutate)
## # A tibble: 6 × 11
##   iso2c iso3c country   year gdp_percap population birth…¹ neona…² region income
##   <chr> <chr> <chr>    <dbl>      <dbl>      <dbl>   <dbl>   <dbl> <chr>  <chr> 
## 1 ZW    ZWE   Zimbabwe  2009      1229.   13720997    36.1    25.2 Sub-S… Low i…
## 2 ZW    ZWE   Zimbabwe  2010      1361.   13973897    36.3    25.3 Sub-S… Low i…
## 3 ZW    ZWE   Zimbabwe  2011      1524.   14255592    36.3    25.1 Sub-S… Low i…
## 4 ZW    ZWE   Zimbabwe  2012      1679.   14565482    36.1    24.8 Sub-S… Low i…
## 5 ZW    ZWE   Zimbabwe  2013      1743.   14898092    35.7    24.4 Sub-S… Low i…
## 6 ZW    ZWE   Zimbabwe  2014      1798.   15245855    35.2    23.9 Sub-S… Low i…
## # … with 1 more variable: gdp_trillion <dbl>, and abbreviated variable names
## #   ¹​birth_rate, ²​neonat_mortal_rate

Selecting top 4 GDPs in Sub-Saharan Africa

top_4_african<-
  filter(nations_mutate, country %in% c("Nigeria", "South Africa", "Ethiopia", "Angola"))

top_4_african
## # A tibble: 100 × 11
##    iso2c iso3c country  year gdp_percap population birth…¹ neona…² region income
##    <chr> <chr> <chr>   <dbl>      <dbl>      <dbl>   <dbl>   <dbl> <chr>  <chr> 
##  1 AO    AGO   Angola   1992      2836.   11848971    52.5    59.4 Sub-S… Lower…
##  2 AO    AGO   Angola   1991      3076.   11472173    52.6    59.2 Sub-S… Lower…
##  3 AO    AGO   Angola   1999      2972.   14601983    51.3    58.7 Sub-S… Lower…
##  4 AO    AGO   Angola   2004      3257.   17295500    49.9    56.7 Sub-S… Lower…
##  5 AO    AGO   Angola   2007      5613.   19183907    48.9    55   Sub-S… Lower…
##  6 AO    AGO   Angola   2003      2962.   16691395    50.2    57.2 Sub-S… Lower…
##  7 AO    AGO   Angola   1996      2603.   13424813    51.9    59.5 Sub-S… Lower…
##  8 AO    AGO   Angola   1997      2779.   13801868    51.7    59.4 Sub-S… Lower…
##  9 AO    AGO   Angola   2010      6361.   21219954    47.5    52.6 Sub-S… Lower…
## 10 AO    AGO   Angola   2001      3132.   15562791    50.7    58.2 Sub-S… Lower…
## # … with 90 more rows, 1 more variable: gdp_trillion <dbl>, and abbreviated
## #   variable names ¹​birth_rate, ²​neonat_mortal_rate

Visualizing Top 4 Economies in Sub-Saharan Africa

ggplot(top_4_african, aes(x=year, y=gdp_trillion, group=country, color=country)) +
  geom_line()+
  geom_point()+
  scale_color_brewer(palette="Set1")+
  labs(x="Year", y="GDP ($ trillion)", title = "Nigeria Leads Sub-Saharan Economies", color ="")+
  theme_minimal()

Summarizing GDP by World Bank Region

gdp_region<-nations_mutate|>
  group_by(region, year)|>
  summarise(GDP = sum(gdp_trillion, na.rm = TRUE))
## `summarise()` has grouped output by 'region'. You can override using the
## `.groups` argument.
gdp_region
## # A tibble: 175 × 3
## # Groups:   region [7]
##    region               year   GDP
##    <chr>               <dbl> <dbl>
##  1 East Asia & Pacific  1990  5.52
##  2 East Asia & Pacific  1991  6.03
##  3 East Asia & Pacific  1992  6.50
##  4 East Asia & Pacific  1993  7.04
##  5 East Asia & Pacific  1994  7.64
##  6 East Asia & Pacific  1995  8.29
##  7 East Asia & Pacific  1996  8.96
##  8 East Asia & Pacific  1997  9.55
##  9 East Asia & Pacific  1998  9.60
## 10 East Asia & Pacific  1999 10.1 
## # … with 165 more rows

Visualizing GDP by World Bank Region

ggplot(gdp_region, aes(x=year, y=GDP, group=region, fill=region)) +
  geom_area(color="white")+
  scale_fill_brewer(palette="Set2")+
  labs(x="Year", y="GDP ($ trillion)", title = "GDP by World Bank Region")+
  theme_minimal()