Nations Dataset Charts Assignment

Author

Lydia B.

setwd("C:/Users/lydia/Downloads/Comms/data 110")
nations <- read.csv("nations.csv")
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.3     ✔ 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(dplyr)
head(nations)
  iso2c iso3c country year gdp_percap population birth_rate neonat_mortal_rate
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.0
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
                 region      income
1 Europe & Central Asia High income
2 Europe & Central Asia High income
3 Europe & Central Asia High income
4 Europe & Central Asia High income
5 Europe & Central Asia High income
6 Europe & Central Asia High income
nations_1 <- nations |> mutate(
    gdp_trillions = 
      (gdp_percap*population)/1000000000000
    )
nations_2 <- nations_1 |>
  filter(country == "China" | country == "Germany" |
           country == "Japan" | country == "United States")
ggplot(nations_2, aes(year,gdp_trillions, colour = country))+
scale_color_brewer(palette = "Set1", name = "Country")+
geom_point()+
geom_line(linewidth = 0.7)+
labs(title = "China's Rise to Become the Largest Economy")+
xlab("Year") +
ylab ("GDP (Trillions of $)")+
theme_minimal()

nations_3 <- nations_1 |>
  group_by(region, year)|>
 summarise(GDP = sum(
   gdp_trillions, na.rm =TRUE
   ))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
nations_3
# A tibble: 175 × 3
# Groups:   region [7]
   region               year   GDP
   <chr>               <int> <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
 7 East Asia & Pacific  1996  8.96
 8 East Asia & Pacific  1997  9.55
 9 East Asia & Pacific  1998  9.60
10 East Asia & Pacific  1999 10.1 
# ℹ 165 more rows
ggplot(nations_3, aes(year,GDP, fill = region))+
scale_fill_brewer(palette = "Set2", name = "Region")+
geom_area (color = "white", size = 0.1)+
labs(title = "GDP by World Bank Region")+
xlab("Year") +
ylab ("GDP ($ trillions)")+
theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.