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.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()
library(dplyr)
library(ggplot2)
setwd("~/School/MC/DATA 110/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)
## # A tibble: 6 x 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
## # ... with 2 more variables: region <chr>, income <chr>
#create a new variable, GDP of each country in trillions of dollars
nations_withGDP <- mutate(nations, gdp = gdp_percap * population / 1e12)
Plot 1. EU’s Big Four Economies
nations_withGDP %>%
filter(country == "Spain" |
country == "Germany" |
country == "France" |
country == "United Kingdom") %>%
ggplot(mapping = aes(x = year, y = gdp, color = country)) +
geom_point() +
geom_line() +
scale_color_brewer(palette = "Set1") +
labs(x = "Year",
y = "GDP in trillions of dollars",
title = "EU's Big Four Economies",
subtitle = "GDP of Germany, United Kingdom, France, and Spain from 1990 to 2014")
Plot 2. Region’s GDP Area Chart
nations_withGDP %>%
group_by(region, year) %>%
summarise(gdp = sum(gdp, na.rm = TRUE)) %>%
ggplot(mapping = aes(x = year, y = gdp, fill = region)) +
geom_area() +
scale_fill_brewer(palette = "Set2") +
labs(x = "Year",
y = "GDP in trillions of dollars",
title = "Region's GDP Area Chart",
subtitle = "From 1990 to 2014")
## `summarise()` has grouped output by 'region'. You can override using the `.groups` argument.