Load the libraries
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Set the Working Directory
projectoneWD <- "C:/Users/Joeyc/Documents/School/Fall 2020/Data 110/Datasets"
setwd(projectoneWD)
getwd()
## [1] "C:/Users/Joeyc/Documents/School/Fall 2020/Data 110/Datasets"
Loading in the data
Joey <- read.csv(file.choose())
Mutate the GDP to show in trillions of dollars
Joey2 <- mutate(Joey, gdp = ((gdp_percap * population)/1000000000000))
Chart 1
JoeyC <- filter(Joey2, country == "Nigeria"|country == "Ethiopia" | country == "Egypt, Arab Rep." | country == "Congo, Dem. Rep." )
ggplot (JoeyC, aes( y = gdp, x = year, color = country)) +
xlab("Year") +ylab("GDP($ trillion)") +
ggtitle("GDP of Most Populated African Countries") +
geom_point() +
geom_line() + scale_color_brewer(palette = 'Set1')
## Warning: Removed 1 rows containing missing values (geom_point).
## Warning: Removed 1 row(s) containing missing values (geom_path).

Joey3 <- Joey2 %>% group_by(region, year) %>% summarise(gdp = sum(gdp, na.rm = TRUE))
Chart 2
ggplot(Joey3, aes(x = year, y = gdp)) +
xlab("Year") + ylab("GDP($ trillion)") +
ggtitle("GDP by Region") +
geom_area(colour = "white", aes(fill = region)) + scale_fill_brewer(palette = 'Set2')
