Nations Dataset HW

Author

Allan Maino Vieytes

Library & Loading of Nations.csv

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── 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(plotly)

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout
library(revealjs)
setwd("E:/data-110")
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>

Creation of Nations.2

nations.2 <- nations %>%
  mutate( gdp.in.trill = ( gdp_percap * population ) / 1000000000) %>%
  select( year, gdp.in.trill, country ) %>%
  filter( country %in% c( "Brazil", "United States", "Chile", "China" ))

Nations.2 Line Graph (non-Interactive)

p.1 <- ggplot( data = nations.2, mapping = aes( y = gdp.in.trill, x = year, color = country ) ) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1") +
  theme_bw() +
  labs( title = "BRICS: China's Dominance & Brazil's Undeveloped Potential", color = "Country" ) +
  ylab( "GDP ($Trillion)" ) +
  xlab( "Year (1990-2015)" ) +
  theme( legend.position = c(0.15,0.8)) +
  theme( plot.title = element_text(hjust = 0.5) )
p.1

P.1 (Interactive)

p.1 <- ggplotly(p.1)
p.1

Creation of nations.3

nations.3 <- nations %>%
  mutate( gdp.in.trill = ( gdp_percap * population ) / 1000000000) %>%
  group_by( region, year ) %>%
  summarise( sum_GDP = sum( gdp.in.trill, na.rm = TRUE ) )
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.

nations.3 Area Plot (non-Interactive)

p.2 <- ggplot( data = nations.3, mapping = aes( y = sum_GDP, x = year, fill = region, ) ) +
  geom_area( color = "white") + 
  scale_fill_brewer(palette = "Set2") +
  theme_bw(10) +
  labs( title = "GDP by Region: East Asia & Pacific Ahead of the Pack", fill = "Region" ) +
  ylab( "GDP ($Trillion)" ) +
  xlab( "Year (1990-2015)" ) +
  theme(aspect.ratio =0.6,
        axis.text = element_text(colour = 1, size = 12),
        legend.background = element_blank(),
        legend.box.background = element_rect(colour = "black"),
        legend.position = c(0.17,0.7),
        plot.title = element_text(hjust = 0.5))
p.2

nations.3 Area Plot (Interactive)

p.2 <- ggplotly(p.2)
Warning: Aspect ratios aren't yet implemented, but you can manually set a
suitable height/width

Warning: Aspect ratios aren't yet implemented, but you can manually set a
suitable height/width
p.2