##Draw both charts with ggplot2.

####For the first chart, you will need to filter the data with dplyr for the four desired countries. When making the chart with ggplot2 you will need to add both geom_point and geom_line layers, and use the Set1 ColorBrewer palette using: scale_color_brewer(palette = “Set1”). ##For the second chart, using dplyr you will need to group_by region and year, and then summarize on your mutated ##value for gdp using
##summarise(GDP = sum(gdp, na.rm = TRUE)). (There will be null values, or NAs, in this data, so you will need to use ##na.rm = TRUE). ##Each region’s area will be generated by the command geom_area () #When drawing the chart with ggplot2, you will need to use the Set2 ColorBrewer palette using scale_fill_brewer(palette = “Set2”)

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
library(ggplot2)
library(readr)
library(scales)
## 
## Attaching package: 'scales'
## The following object is masked from 'package:readr':
## 
##     col_factor
gdp <- read.csv(file = "nations.csv")
gdp1 <- mutate(gdp, GDP = ((gdp_percap * population)/1000000000000))
gdp2 <- filter(gdp1, country == "China" | country == "Germany" | country == "Japan" | country == "United States")
ggplot (gdp2, aes(x = year, y = GDP, color = country)) +
  ylab("GDP($ trillion)") +
  theme_minimal(base_size = 12) +
  ggtitle("China's Rise to Become the Largest Economy") +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = 'Set1')

gdp3 <- gdp1 %>% group_by(region, year) %>% summarise(GDP = sum(GDP, na.rm = TRUE))
## `summarise()` has grouped output by 'region'. You can override using the
## `.groups` argument.
ggplot(gdp3, aes(year, GDP)) +
         xlab("year") + ylab("GDP($ trillion)") +
         theme_minimal(base_size = 12) +
         scale_fill_brewer(palette = 'Set2') +
         ggtitle("GDP by Word Bank Region") +
         geom_area(colour = "white", aes(fill = region))