library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.0.6     v dplyr   1.0.3
## 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("C:/Users/noahz/Desktop/Data 110 R/Datasets/Hate crime data sets")
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()
## )
nations_GDP <- nations%>%
  mutate(GDP = (gdp_percap * population)/1000000000000) %>%
  filter(iso3c == "ARE" | iso3c == "GBR" | iso3c == "FRA" | iso3c == "DEU")
nations_GDP
## # A tibble: 100 x 11
##    iso2c iso3c country  year gdp_percap population birth_rate neonat_mortal_r~
##    <chr> <chr> <chr>   <dbl>      <dbl>      <dbl>      <dbl>            <dbl>
##  1 AE    ARE   United~  1991     73037.    1913190       24.6              7.9
##  2 AE    ARE   United~  1993     71960.    2127863       22.4              7.3
##  3 AE    ARE   United~  2001     83534.    3217865       15.8              5.5
##  4 AE    ARE   United~  1992     73154.    2019014       23.5              7.6
##  5 AE    ARE   United~  1994     74684.    2238281       21.3              6.9
##  6 AE    ARE   United~  2007     75427.    6010100       12.8              4.7
##  7 AE    ARE   United~  2004     87844.    3975945       14.2              5.1
##  8 AE    ARE   United~  1996     79480.    2467726       19.3              6.4
##  9 AE    ARE   United~  2006     82754.    5171255       13.3              4.9
## 10 AE    ARE   United~  2000     84975.    3050128       16.4              5.6
## # ... with 90 more rows, and 3 more variables: region <chr>, income <chr>,
## #   GDP <dbl>
summary(nations_GDP)
##     iso2c              iso3c             country               year     
##  Length:100         Length:100         Length:100         Min.   :1990  
##  Class :character   Class :character   Class :character   1st Qu.:1996  
##  Mode  :character   Mode  :character   Mode  :character   Median :2002  
##                                                           Mean   :2002  
##                                                           3rd Qu.:2008  
##                                                           Max.   :2014  
##    gdp_percap      population         birth_rate    neonat_mortal_rate
##  Min.   :17446   Min.   : 1811458   Min.   : 8.10   Min.   :2.200     
##  1st Qu.:24233   1st Qu.:45207224   1st Qu.:10.99   1st Qu.:2.700     
##  Median :34657   Median :60448960   Median :12.60   Median :3.200     
##  Mean   :40656   Mean   :52109693   Mean   :12.67   Mean   :3.657     
##  3rd Qu.:48857   3rd Qu.:69730212   3rd Qu.:13.10   3rd Qu.:4.225     
##  Max.   :87844   Max.   :82534176   Max.   :25.77   Max.   :8.200     
##     region             income               GDP        
##  Length:100         Length:100         Min.   :0.1341  
##  Class :character   Class :character   1st Qu.:0.9034  
##  Mode  :character   Mode  :character   Median :1.6934  
##                                        Mean   :1.5896  
##                                        3rd Qu.:2.2692  
##                                        Max.   :3.7571
GDPs <- ggplot(nations_GDP, aes(x = year, y = GDP)) + 
  labs(title = "GDP of 5 Countries") +
       xlab("Year") +
       ylab("GDP ($trillions)") +
  theme_minimal(base_size = 13)
GDPs +
  geom_line(aes(color = country)) +
  geom_point(aes(color = country)) +
  scale_color_brewer(palette = "Set1")

nations_test <- nations %>%
  mutate(GDP = (gdp_percap * population)/1000000000000) %>%
  group_by(region, year) %>%
  summarise(GDP = sum(GDP, na.rm = TRUE))
## `summarise()` has grouped output by 'region'. You can override using the `.groups` argument.
GDP_area <- ggplot(nations_test) +
  labs(title = "GDP by World Bank Region") +
       xlab("Year") +
       ylab("GDP ($trillions)") +
  theme_minimal(base_size = 13)
GDP_area +
  geom_area(aes(x = year, y = GDP, fill = region)) +
  scale_fill_brewer(palette = "Set2")