library(ggplot2)
library(dplyr)
library(highcharter)
## Warning: package 'highcharter' was built under R version 4.3.1
library(RColorBrewer)
library(tidyverse)
## Warning: package 'tidyr' was built under R version 4.3.1
library(scales)
## Warning: package 'scales' was built under R version 4.3.1
setwd ("C:\\Users\\asing\\Desktop\\data_science\\data_110\\week_4")
nations <- read_csv("nations.csv")
nations2 <- mutate(nations,gdp_tn = gdp_percap*population/10^12)
Check the headings of the data set
head(nations2)
## # A tibble: 6 × 11
## 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
## # ℹ 3 more variables: region <chr>, income <chr>, gdp_tn <dbl>
#View(nations)
Filtering the data set and getting BRICS which is Brazil, Russia,
India, China, and South Africa
big5 <- nations2 %>%
filter(iso3c == "BRA" | iso3c == "RUS" | iso3c == "IND" | iso3c == "CHN" | iso3c == "ZAF") %>%
arrange(year)
Graphing BRICS Nations by GGPLOT
ggplot(big5, aes(x= year, y = gdp_tn, color = country))+
theme_minimal(base_size = 15)+
labs(title= "BRICS NATIONS")+
xlab("Years") +
ylab("GDP ($ Trillion)")+
geom_point()+
geom_line()+
scale_color_brewer(palette = "Set1")

Prepareing Data for Second Graph
gdpworldbank <- nations2 %>% group_by(region,year) %>% summarize(gdp_tn = sum(gdp_tn, na.rm = TRUE))
Lets check the Data
head(gdpworldbank)
## # A tibble: 6 × 3
## # Groups: region [1]
## region year gdp_tn
## <chr> <dbl> <dbl>
## 1 East Asia & Pacific 1990 5.52
## 2 East Asia & Pacific 1991 6.03
## 3 East Asia & Pacific 1992 6.50
## 4 East Asia & Pacific 1993 7.04
## 5 East Asia & Pacific 1994 7.64
## 6 East Asia & Pacific 1995 8.29
Graphing the Data by Region using GGPLOT
p4 <- ggplot(gdpworldbank, aes(x = year, y = gdp_tn)) +
geom_area(aes(fill = region), color = "white") +
xlab("Year") +
ylab("GDP ($ Trillion)") +
theme_minimal(base_size = 15) +
scale_fill_brewer(palette = "Set2")
p4
