part two 6

Assignment 6- Part 2

library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.5.2
Warning: package 'ggplot2' was built under R version 4.5.2
Warning: package 'tibble' was built under R version 4.5.2
library(dplyr)
library(ggplot2)
setwd("C:/Users/kenne/Downloads")
nations <- read_csv("nations.csv")
thenations <- nations |>
  mutate(gdp = (gdp_percap*population)/1000000000000)
head(thenations)
# A tibble: 6 × 11
  iso2c iso3c country  year gdp_percap population birth_rate neonat_mortal_rate
  <chr> <chr> <chr>   <dbl>      <dbl>      <dbl>      <dbl>              <dbl>
1 AD    AND   Andorra  1996         NA      64291       10.9                2.8
2 AD    AND   Andorra  1994         NA      62707       10.9                3.2
3 AD    AND   Andorra  2003         NA      74783       10.3                2  
4 AD    AND   Andorra  1990         NA      54511       11.9                4.3
5 AD    AND   Andorra  2009         NA      85474        9.9                1.7
6 AD    AND   Andorra  2011         NA      82326       NA                  1.6
# ℹ 3 more variables: region <chr>, income <chr>, gdp <dbl>
four_nations <- thenations |>
  filter(country %in% c("China", "Japan", "Germany", "United States"))
head(four_nations)
# A tibble: 6 × 11
  iso2c iso3c country  year gdp_percap population birth_rate neonat_mortal_rate
  <chr> <chr> <chr>   <dbl>      <dbl>      <dbl>      <dbl>              <dbl>
1 CN    CHN   China    1992      1260. 1164970000       18.3               29.4
2 CN    CHN   China    2005      5053. 1303720000       12.4               14  
3 CN    CHN   China    2000      2915. 1262645000       14.0               21.2
4 CN    CHN   China    1991      1091. 1150780000       19.7               29.7
5 CN    CHN   China    2013     12219. 1357380000       12.1                6.3
6 CN    CHN   China    1999      2650. 1252735000       14.6               22.2
# ℹ 3 more variables: region <chr>, income <chr>, gdp <dbl>
four_nations |>
 ggplot(aes(x = year, y = gdp, fill = country, color = country)) +
  geom_point() +
  geom_line() +
  ylab("GDP") +
  scale_color_brewer(palette = "Set1")

group_graph <- four_nations |>
  group_by(region, year) |>
  summarise(GDP = sum(gdp, na.rm = TRUE))
group_graph |>
  ggplot(aes(x = year, y = GDP, fill = region, color = region)) + geom_area(color = "black") + ylab("GDP") +
  scale_fill_brewer(palette = "Set2")