DATA HW5

Author

Ehiggs

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.2
✔ ggplot2   4.0.0     ✔ 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(RColorBrewer)
setwd("C:/Users/emmam/OneDrive/Documents/Data 110")

nations <- read.csv("nations.csv")
gdpgraph <- nations |>
  mutate(newGDP = gdp_percap * population/1000000000)
highestPopulation <- gdpgraph |>
  c("China" , "India" , "United States" , "Indonesia")
gdpFilter <- gdpgraph |>
    filter(country %in% (highestPopulation))
chart1 <- gdpFilter |>
  ggplot(aes(x = year , y = newGDP, fill = country, group = country, color = country)) + 
  geom_line(position = "identity") +
  scale_color_brewer(palette = "Set1") +
  labs(title = "country", x = "Year", y = "GDP ($ trillions)", caption = "Nations dataset") +
  geom_point() +
  
  theme_minimal()
        
chart1

reigonYear <- gdpgraph |>
  group_by(year, region) |> 
  summarise(sum_GDP = sum(newGDP, na.rm = TRUE))
`summarise()` has grouped output by 'year'. You can override using the
`.groups` argument.
plot2 <- reigonYear |>
  ggplot(aes(fill = region, x= year, y= sum_GDP, group = region))+
  geom_area (position = "stack")+
  theme_minimal()+
  geom_area(color= "white", position = "stack")+
  scale_fill_brewer(palette = "Set2")+
  labs(y = "GDP", x = "Year", title = "GDP by World Bank Region")
  
plot2