getwd()[1] "C:/Users/mezni/OneDrive/Desktop/Data 110"
getwd()[1] "C:/Users/mezni/OneDrive/Desktop/Data 110"
library(tidyverse)Warning: package 'ggplot2' was built under R version 4.5.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.1 ✔ stringr 1.5.2
✔ ggplot2 4.0.2 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.1.0
── 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)
library(ggplot2)
setwd("C:/Users/mezni/OneDrive/Desktop/HWK Nation")
nation <- read_csv('HAMA.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.
nation_1 <- nation |>
mutate(gdp_percountry = gdp_percap * population / 10 ^ 12) |>
filter(country %in% c("Tunisia","Italy", "Colombia", "Brazil"))ggplot(data = nation_1, aes(x = year, y = gdp_percountry, color = country)) +
geom_line() +
geom_point() +
scale_color_brewer(palette = "Set1") +
labs(title = "Brazil's rise to Become the largest economy",
y = "GDP ($trillions)")nation_2 <- nation |>
mutate(gdp_percountry = gdp_percap * population / 10 ^ 12) |>
group_by(region,year) |>
summarise(gdp = sum(gdp_percountry, na.rm = TRUE)) `summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
ggplot(data = nation_2, aes(x = year, y = gdp, fill = region)) +
geom_area(alpha = 0.7, color = "white") +
scale_fill_brewer(palette = "Set2")I chose Tunisia because it’s my home country(I know our GDP is awaful, but I still love my country). I chose Italy because it’s the best country I have ever visted. I also chose Brazil and Colombia because I’m planing to visit them.