Nations Charts

Author

Kenny Nguyen

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(RColorBrewer)
setwd("~/Desktop/Data 110")
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.
nations2 <- nations |>
  mutate(gdp = gdp_percap * population / 10^12)|>
na.omit(data$gdp)
nations2
# A tibble: 4,303 × 11
   iso2c iso3c country  year gdp_percap population birth_rate neonat_mortal_rate
   <chr> <chr> <chr>   <dbl>      <dbl>      <dbl>      <dbl>              <dbl>
 1 AE    ARE   United…  1991     73037.    1913190       24.6                7.9
 2 AE    ARE   United…  1993     71960.    2127863       22.4                7.3
 3 AE    ARE   United…  2001     83534.    3217865       15.8                5.5
 4 AE    ARE   United…  1992     73154.    2019014       23.5                7.6
 5 AE    ARE   United…  1994     74684.    2238281       21.3                6.9
 6 AE    ARE   United…  2007     75427.    6010100       12.8                4.7
 7 AE    ARE   United…  2004     87844.    3975945       14.2                5.1
 8 AE    ARE   United…  1996     79480.    2467726       19.3                6.4
 9 AE    ARE   United…  2006     82754.    5171255       13.3                4.9
10 AE    ARE   United…  2000     84975.    3050128       16.4                5.6
# ℹ 4,293 more rows
# ℹ 3 more variables: region <chr>, income <chr>, gdp <dbl>
cc <- nations2 |>
select("country","gdp", "year")
cc
# A tibble: 4,303 × 3
   country                gdp  year
   <chr>                <dbl> <dbl>
 1 United Arab Emirates 0.140  1991
 2 United Arab Emirates 0.153  1993
 3 United Arab Emirates 0.269  2001
 4 United Arab Emirates 0.148  1992
 5 United Arab Emirates 0.167  1994
 6 United Arab Emirates 0.453  2007
 7 United Arab Emirates 0.349  2004
 8 United Arab Emirates 0.196  1996
 9 United Arab Emirates 0.428  2006
10 United Arab Emirates 0.259  2000
# ℹ 4,293 more rows
fourc <- cc |>
  filter(country %in% c("China","Japan","Germany","United States"))
fourc
# A tibble: 100 × 3
   country   gdp  year
   <chr>   <dbl> <dbl>
 1 China    1.47  1992
 2 China    6.59  2005
 3 China    3.68  2000
 4 China    1.26  1991
 5 China   16.6   2013
 6 China    3.32  1999
 7 China   18.1   2014
 8 China    5.07  2003
 9 China    5.73  2004
10 China    1.71  1993
# ℹ 90 more rows
nations_graph <- ggplot(fourc, aes(x =year, y = gdp, color=country,)) +
  geom_point() +
  geom_line()+
  scale_color_brewer(palette ="Set 1") +
  labs( title = "China's Rise To Become The Largest Economy",
    x = "year",
    y = "GDP (Trillion$)" )+
  theme_minimal(base_size = 14) 
Warning: Unknown palette: "Set 1"
nations_graph 

Graph2 <-  nations2 |>
  group_by(region,year) |>
summarise(sum_GDP = sum(gdp, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
Graph2
# A tibble: 175 × 3
# Groups:   region [7]
   region               year sum_GDP
   <chr>               <dbl>   <dbl>
 1 East Asia & Pacific  1990    5.41
 2 East Asia & Pacific  1991    5.91
 3 East Asia & Pacific  1992    6.37
 4 East Asia & Pacific  1993    6.90
 5 East Asia & Pacific  1994    7.49
 6 East Asia & Pacific  1995    8.13
 7 East Asia & Pacific  1996    8.80
 8 East Asia & Pacific  1997    9.37
 9 East Asia & Pacific  1998    9.43
10 East Asia & Pacific  1999    9.97
# ℹ 165 more rows
P2 <- ggplot(Graph2, aes(x = year, y = sum_GDP, fill = region)) + 
  geom_area(color = "white", size = 0.25) + 
  scale_fill_brewer(palette = "Set2")+
  labs(title = "GDP by World Bank Region", 
       x = "Year", 
       y = "GDP (Trillion $)", 
       fill= "Region") + 
  theme_minimal(base_size = 14)+ 
  theme(panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank())
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
P2