load needed liberary

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ ggplot2 3.3.6     ✔ purrr   0.3.4
## ✔ tibble  3.1.7     ✔ dplyr   1.0.9
## ✔ tidyr   1.2.0     ✔ stringr 1.4.0
## ✔ readr   2.1.2     ✔ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()

load nation dataset

setwd("C:/Users/baise/OneDrive/Desktop/Baidata110summer")
nations <- read_csv("nations.csv")
## Rows: 5275 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): iso2c, iso3c, country, region, income
## dbl (5): year, gdp_percap, population, birth_rate, neonat_mortal_rate
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

view nations in full

view(nations)

Loading rcolorBrewer and big four country

library(RColorBrewer)
nation <- nations %>%
  mutate(gdp_tn = gdp_percap*population/10^12) %>%
  filter(iso3c == "NOR" | iso3c == "BMU" | iso3c == "AUS" | iso3c == "CAN") %>%
  arrange(year)

First plot, plot one

plot1 <- nation %>%
  ggplot(aes(year, gdp_tn, color = country))+
  geom_point()+
  geom_line()+ #theme(legend.title = none)+
  scale_color_discrete(name =  " ")+
  theme_bw()+
  geom_point()+
  geom_line()+
  scale_color_brewer(palette = "Set1")+
  ggtitle("Growth of Nations")+
  xlab("Year")
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
plot1
## Warning: Removed 1 rows containing missing values (geom_point).
## Warning: Removed 1 row(s) containing missing values (geom_path).
## Warning: Removed 1 rows containing missing values (geom_point).
## Warning: Removed 1 row(s) containing missing values (geom_path).

Plot two and cleaning NA values

nation2 <- nations %>%
  group_by(region, year) %>%
  mutate(gdp_tn = gdp_percap*population/10^12) %>%
  summarise(sum = sum(gdp_tn, na.rm = TRUE))
## `summarise()` has grouped output by 'region'. You can override using the
## `.groups` argument.
plot2 <- nation2 %>%
  ggplot(aes(year, sum, fill = region))+
  geom_area()+
  scale_fill_brewer(palette = "Set2")+ scale_color_discrete(name =  " ")+
  geom_area(color="white") +
  ggtitle("GDP by World Bank Region")+
  xlab("Year")+
  ylab("GDP in Trillions of Dollars")
plot2