library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v tibble  3.0.6     v purrr   0.3.4
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
setwd("~/DATA 110/R_Datasets")
nations <- read_csv("nations.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   iso2c = col_character(),
##   iso3c = col_character(),
##   country = col_character(),
##   year = col_double(),
##   gdp_percap = col_double(),
##   population = col_double(),
##   birth_rate = col_double(),
##   neonat_mortal_rate = col_double(),
##   region = col_character(),
##   income = col_character()
## )
head(nations)
nations.mutated <- nations %>%
  mutate(GDP_trillion = (gdp_percap*population)/1000000000000)
head(nations.mutated)
chart1 <- nations.mutated %>%
  select(country, year, GDP_trillion) %>%
  filter(country %in% c("China", "United States", "United Arab Emirates", "Australia", "India", "Japan"))
head(chart1)
library(RColorBrewer)
chart1_vis <- ggplot(chart1, aes(x=year, y=GDP_trillion, group=country, color=country))+
  geom_line() + geom_point()+
  scale_color_brewer(palette = "Set1")+
  ggtitle("The Growth of Country's Economies in the World")+
  xlab("Year")+
  ylab("GDP ($ Trillion)")
chart1_vis

chart2 <- nations.mutated %>%
  group_by(region, year) %>%
  summarize(GDP = sum(GDP_trillion, na.rm = TRUE))
## `summarise()` has grouped output by 'region'. You can override using the `.groups` argument.
head(chart2)
chart2_vis <- ggplot(chart2, aes(x=year, y=GDP, fill=region)) + 
  geom_area(alpha=0.6 , size=.5, colour="white")+
  scale_fill_brewer(palette = "Set2") +
  ggtitle("GDP by World Bank Region")+
  xlab("Year")+
  ylab("GDP ($ Trillion)") 
chart2_vis