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)
setwd("C:/Users/MCuser/Downloads")
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.
nation1 <- nations |>
mutate(gdppop = gdp_percap*population/1000000000) |>
filter(country %in% c("Italy", "Austria", "Romania", "Germany"))
nation1 |>
ggplot(aes(x = year, y = gdppop, color = country)) +
geom_point() +
geom_line() +
labs(title = "Comparison of GDP in trillions by country",
y = "GDP (trillions of $)",
x = "Year",
color = "Country") +
scale_color_brewer(palette = "Set1")+
theme_light()

nation2 <- nations |>
mutate(gdppop = gdp_percap*population/1000000000) |>
group_by(year,region) |>
summarize(gdppop = sum(gdppop, na.rm = TRUE))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
nation2 |>
ggplot(aes(x=year, y=gdppop, fill = region)) +
geom_area() +
scale_fill_brewer(palette = "Set2") +
labs(title = "GDP by World Bank Region",
x = "Year",
y = "GDP($ Trillions)") +
theme_light()
