#Loading……
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(readr)
library(ggplot2)
library(dplyr)
library(RColorBrewer)
#Read Nations Dataset
nations <- read.csv("Data110Code/nations.csv")
#COLORS
display.brewer.all()
#Filter the data with dplyr for the four desired countries
Nations1 <- nations %>%
select(year, birth_rate, population, gdp_percap, country) %>%
mutate(GDP = ((gdp_percap * population) / 1e+12) ) %>%
arrange(year)
#Dimensions and Structure
dim(Nations1)
## [1] 5275 6
str(Nations1)
## 'data.frame': 5275 obs. of 6 variables:
## $ year : int 1990 1990 1990 1990 1990 1990 1990 1990 1990 1990 ...
## $ birth_rate: num 11.9 25.8 49 18.8 24.8 ...
## $ population: num 54511 1811458 12067570 61906 3286542 ...
## $ gdp_percap: num NA 74017 NA 11087 2749 ...
## $ country : chr "Andorra" "United Arab Emirates" "Afghanistan" "Antigua and Barbuda" ...
## $ GDP : num NA 0.134079 NA 0.000686 0.009033 ...
Nations_Country <- Nations1 %>%
filter(country %in% c("Cambodia", "Thailand", "Lao PDR", "Vietnam")) %>%
ggplot(aes (x= year, y= GDP)) +
labs(title= "Thailand's Economic Growth Comparared to Surrounding Countries") +
xlab("Years")+
ylab("GDP by Trillion") +
theme_minimal(base_size = 10)
#ADD points, lines, color
FNC <- Nations_Country +
geom_point(aes(color= country)) + geom_line(aes(color= country))
labs(color= "Country") +
scale_color_brewer(palette = "Set1")
## NULL
#Visualization Here
FNC
## Warning: Removed 3 rows containing missing values (geom_point).
## Warning: Removed 3 row(s) containing missing values (geom_path).
#2 Group by region and year, and then summarize on your mutated value
for gdp
RegionalData <- nations %>%
mutate(GDP2 = (gdp_percap * population / 1e+12))
RegionalYear <- RegionalData %>%
group_by(year, region) %>%
summarise(GDP2 = sum(gdp_percap, na.rm = TRUE)) %>%
arrange(year, region)
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
FRD <- ggplot() +
geom_area(data = RegionalYear, aes(x = year, y = GDP2, fill = region), color = "white") +
ggtitle("Gross Domestic Product by World Bank (by Region)" ) +
labs(
xlab = "Year",
ylab = "GDP by trillions") +
theme_minimal(base_size = 10) +
scale_fill_brewer(name = "Region", palette = "Set2")
#Visualization Here
FRD