Nations Charts Assignment

Author

Arthur De Almeida

#calling all packages and data:
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/Usuário/Documents/Data110")
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.
# Mutating the data set to create the GDP in trillion
gdp_nations <- nations %>%
  mutate(gdp_trillions = (gdp_percap * population) / 1e12)
#Filtering fro the 4 countries on the original visualization
filtered_nations <- gdp_nations %>%
  filter(country %in% c("China", "Germany", "Japan", "United States"))
#After all the filtering there is just the plot
plot_line_point <- filtered_nations |>
ggplot(aes(x=year, y=gdp_trillions, color = country)) + #Defining the axis
  geom_point() + #Inserting the type of geometry for the graph
  geom_line() + #Ading the second layer so it is a line pointr graph
labs(x = "Year", y = "GDP($ trillion)", title = "China`s Rise to Become the Largest Economy", caption = "Data from the class data folder") + #captions for the visualization
  theme_bw() +
  theme(panel.border = element_blank() #changing the background
  ) +
  scale_color_brewer(palette = "Set1") #captions for the visualization
plot_line_point

summarized_gdp <- gdp_nations %>%
  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.
plot_area <- summarized_gdp |>
  ggplot(aes(x = year, y =GDP, fill = region)) + #Defining the axis
  geom_area(color = "White", linwwidth = 0.5) + #inserting the withe line between the areas and using geom_area for the area plot
  theme_bw() +
  theme(panel.border = element_blank() #changing the background
  ) +
  scale_fill_brewer(palette = "Set2") + #setting the color pallet
  labs(x = "Year", y= "GDP($ trillion)", title = "GDP by Word Bank Nation", caption = "Data from the class data folder") #captions for the visualization
Warning in geom_area(color = "White", linwwidth = 0.5): Ignoring unknown
parameters: `linwwidth`
plot_area