In this file we’re creating 2 graphs

Graph 1. Provides a trend of GDP on Central American Nations
Graph 2. Provides a trend on aggregated GDP by World Regions.

Read in CSV file & take a look at the data

Nations <- read.csv("/Users/cruz-diazgroup/Desktop/1. William/1. School/DATA SCIENCE/2. DATA 110 Vis. & Com./1. HW/nations.csv", check.names = FALSE, header = TRUE, sep = ",") 
# Look at the data
#head(Nations)
I now create the variable “GDP” for the entire data before filtering out my nations for the first graph.
# I load the library I'll be using
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.3     ✓ purrr   0.3.4
## ✓ tibble  3.1.0     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
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
Nations <-Nations %>%
  mutate(GDP = (gdp_percap * population) / 10^12 )
#tail(Nations)
For the first graph, I will be looking at information specific to Central America so I’ll filter out 4 countries: Guatemala, El Salvador, Honduras, & Nicaragua and subset my data
Nations1 <- Nations %>%
  dplyr::filter(country %in% c("Guatemala","El Salvador","Honduras","Nicaragua"))
And..now I graph the data subset
p1 <-ggplot(Nations1, aes(year, GDP, colour = country)) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = "Set1") +
  labs(title = "GDP: Central American Nations") +
  xlab("year") +
  ylab("GDP ($ trillions)") +
  theme_minimal(base_size = 10)
p1 <-ggplotly(p1)
p1
For the second graph I need to group and summarize the data to obtain aggregated values for my area graph
Nations2 <-Nations %>%
  group_by(region, year)%>%
  summarise(GDP = sum(GDP, na.rm = TRUE))
## `summarise()` regrouping output by 'region' (override with `.groups` argument)
p2 <-ggplot(Nations2, aes(year, GDP, fill = region)) +
  geom_area(color = "white", size = .30) +
  scale_fill_brewer(palette = "Set2") +
  labs(title = "World GDP by Region") +
  xlab("year") +
  ylab("GDP ($ trillions)") +
  theme_minimal(base_size = 10)
p2 <-ggplotly(p2)
p2