Nations Charts

Author

Linh Le

Load the dataset

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
✔ ggplot2 3.4.0     ✔ purrr   1.0.1
✔ tibble  3.1.8     ✔ dplyr   1.1.0
✔ tidyr   1.3.0     ✔ stringr 1.5.0
✔ readr   2.1.3     ✔ forcats 0.5.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(dplyr)
library(ggplot2)
setwd("/Users/Linh/Desktop/DATASETS ")
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.
gdp <- read.csv(file = "nations.csv")
gdp1 <- gdp %>%
  mutate(gdp, GDP = (gdp_percap * population)/ 10^12)
gdp2 <- gdp1 %>%
  filter(country %in% c("United States", "Vietnam", "China", "Japan"))
ggplot(gdp2, aes(x = year, y = GDP, color = country)) +
  labs(title = "China's Rise to Become the Largest Economy") +
  xlab("year") +
  ylab("GDP($ trillion)") +
  theme_minimal(base_size = 12) +
  geom_point() +
  geom_line() +
  scale_color_brewer(palette = 'Set1')

ggplot(gdp2, aes(x = year, y = GDP, color = country)) +
  labs(title = "China's Rise to Become the Largest Economy") +
  xlab("year") +
  ylab("GDP($ trillion)") +
  theme_classic(base_size = 11) +
  geom_point() +
  geom_line() +
scale_color_brewer(palette = 'Set1')

Create the second chart: GDP by World Bank Region

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(x = year, y = GDP, fill = region)) +
  labs(title = " GDP by World Bank Region") +
  xlab("year") +
  ylab("GDP($ trillion)") +
  theme_classic(base_size = 12)+
  geom_area() +
 scale_color_brewer(palette = 'set2')
Warning in pal_name(palette, type): Unknown palette set2