Correlations/Scatterplots/Regressions HW Assignment

Author

J Gazmen

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.4     ✔ 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(ggplot2)
library(dplyr)
setwd("C:/Users/Joanne G/OneDrive/Data110(Spring 2025)/Datasets")
nations_df <- 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.
GDP <- nations_df|>  
  mutate(GDP = (gdp_percap * population)/10^12)
plot1_mod <- GDP |>
  filter(country %in% c("China","Germany","Japan","United States")) 
plot1 <- 
  ggplot(plot1_mod,aes(color = country ,fill = country, x = year, y = GDP  )) +
  labs(title = "China's Rise to Become the Largest Economy ",
       x = "Years",
       y = "GDP($trillions)" ) +
  theme_minimal() +
  scale_fill_manual(values = c("#7F58AF","#64C5EB","#A7226F","#F7DC68")) +
  geom_line(size=1.5) +
  geom_point(size=3)
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
plot1  

plot2_mod <- GDP |>
  group_by(region,year)|>
  summarise(sum_GDP = sum(GDP ,na.rm = TRUE), .groups = "drop")
plot2 <- 
  ggplot(plot2_mod, aes(fill = region, x= year, y = sum_GDP ) ) +
  labs(title = "GDP by World Bank Region ",
       x = "Years",
       y = "GDP($trillions)" ) +
  geom_area(color='white',size=0.1) +
  scale_fill_brewer(palette = "Set2")+
  theme_dark()

plot2