Load the Libraries

library(readr)
library(ggplot2)
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(tidyverse)
## ── Attaching packages ───────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ tibble  3.0.3     ✓ dplyr   1.0.1
## ✓ tidyr   1.1.1     ✓ stringr 1.4.0
## ✓ purrr   0.3.4     ✓ forcats 0.5.0
## ── Conflicts ──────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks plotly::filter(), stats::filter()
## x dplyr::lag()    masks stats::lag()
library(RColorBrewer)

Set WD & CSV File

setwd("/Users/tiffanyking/Desktop/Data 110")
countries <- read_csv("Nations.csv")
## Parsed with 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()
## )

Remove all NA’s

nations <- na.omit(countries)

Mutate GDP

land <- nations %>% mutate(GDP =gdp_percap* population/10^12)

Prepare the data

df1<- land %>%
    select(country, year, GDP) %>%
    filter(country== c("Jamaica", "Barbados","Cuba", "Dominican Republic"))
## Warning in country == c("Jamaica", "Barbados", "Cuba", "Dominican Republic"):
## longer object length is not a multiple of shorter object length
df1
## # A tibble: 24 x 3
##    country   year     GDP
##    <chr>    <dbl>   <dbl>
##  1 Barbados  2007 0.00418
##  2 Barbados  2011 0.00432
##  3 Barbados  1994 0.00230
##  4 Barbados  1997 0.00271
##  5 Barbados  2004 0.00342
##  6 Barbados  2012 0.00441
##  7 Cuba      2011 0.214  
##  8 Cuba      2007 0.182  
##  9 Cuba      1998 0.0852 
## 10 Cuba      1990 0.0937 
## # … with 14 more rows

Plot 1 Outline

Carribean_Chart <- ggplot(df1, aes(x = year, y = GDP)) + 
  xlab("Year") +
  ylab("GDP (Trillions)") +
  theme_minimal(base_size = 14) 
Carribean_Chart

## Line Chart

Carribean_Chart +
  geom_line(aes(color=country)) +
  geom_point(aes(color=country)) +
  ggtitle("GDP by Latin America & Carribean Countries ")

scale_color_brewer(palette = "Set1")
## <ggproto object: Class ScaleDiscrete, Scale, gg>
##     aesthetics: colour
##     axis_order: function
##     break_info: function
##     break_positions: function
##     breaks: waiver
##     call: call
##     clone: function
##     dimension: function
##     drop: TRUE
##     expand: waiver
##     get_breaks: function
##     get_breaks_minor: function
##     get_labels: function
##     get_limits: function
##     guide: legend
##     is_discrete: function
##     is_empty: function
##     labels: waiver
##     limits: NULL
##     make_sec_title: function
##     make_title: function
##     map: function
##     map_df: function
##     n.breaks.cache: NULL
##     na.translate: TRUE
##     na.value: NA
##     name: waiver
##     palette: function
##     palette.cache: NULL
##     position: left
##     range: <ggproto object: Class RangeDiscrete, Range, gg>
##         range: NULL
##         reset: function
##         train: function
##         super:  <ggproto object: Class RangeDiscrete, Range, gg>
##     rescale: function
##     reset: function
##     scale_name: brewer
##     train: function
##     train_df: function
##     transform: function
##     transform_df: function
##     super:  <ggproto object: Class ScaleDiscrete, Scale, gg>

Prepare data for Plot 2

mainland<- land %>%
    select(year, region, GDP) %>%
    group_by(region, year) %>%
    summarize(GDP = sum(GDP, na.rm = TRUE))
## `summarise()` regrouping output by 'region' (override with `.groups` argument)
mainland
## # A tibble: 175 x 3
## # Groups:   region [7]
##    region               year   GDP
##    <chr>               <dbl> <dbl>
##  1 East Asia & Pacific  1990  5.41
##  2 East Asia & Pacific  1991  5.91
##  3 East Asia & Pacific  1992  6.37
##  4 East Asia & Pacific  1993  6.90
##  5 East Asia & Pacific  1994  7.49
##  6 East Asia & Pacific  1995  8.13
##  7 East Asia & Pacific  1996  8.80
##  8 East Asia & Pacific  1997  9.37
##  9 East Asia & Pacific  1998  9.43
## 10 East Asia & Pacific  1999  9.97
## # … with 165 more rows

Plot 2 Outline

Continent_Chart <- ggplot(mainland, aes(x = year, y =GDP)) + 
  xlab("Year") +
  ylab("GDP (Trillions)") +
  theme_minimal(base_size = 14) 
Continent_Chart

Line Chart 2

Continent_Chart +
  geom_line(aes(fill=region)) +
  geom_area(aes(fill=region)) +
  ggtitle("GDP by Region")
## Warning: Ignoring unknown aesthetics: fill

scale_fill_brewer(palette = "Set2")
## <ggproto object: Class ScaleDiscrete, Scale, gg>
##     aesthetics: fill
##     axis_order: function
##     break_info: function
##     break_positions: function
##     breaks: waiver
##     call: call
##     clone: function
##     dimension: function
##     drop: TRUE
##     expand: waiver
##     get_breaks: function
##     get_breaks_minor: function
##     get_labels: function
##     get_limits: function
##     guide: legend
##     is_discrete: function
##     is_empty: function
##     labels: waiver
##     limits: NULL
##     make_sec_title: function
##     make_title: function
##     map: function
##     map_df: function
##     n.breaks.cache: NULL
##     na.translate: TRUE
##     na.value: NA
##     name: waiver
##     palette: function
##     palette.cache: NULL
##     position: left
##     range: <ggproto object: Class RangeDiscrete, Range, gg>
##         range: NULL
##         reset: function
##         train: function
##         super:  <ggproto object: Class RangeDiscrete, Range, gg>
##     rescale: function
##     reset: function
##     scale_name: brewer
##     train: function
##     train_df: function
##     transform: function
##     transform_df: function
##     super:  <ggproto object: Class ScaleDiscrete, Scale, gg>