Assignment 6 Part 2

Author

Javier Mantilla

library(ggplot2)
Warning: package 'ggplot2' was built under R version 4.5.2
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
setwd("~/Documents/Data 110")
nations <- read.csv("nations.csv")
nations <- nations |>
  mutate(gdp_using = (gdp_percap*population)/1000000000000)
nations_new <- nations |>
    filter(country %in% c("China", "Japan", "Germany", "United States"))
head(nations_new)
  iso2c iso3c country year gdp_percap population birth_rate neonat_mortal_rate
1    CN   CHN   China 1992   1260.162 1164970000      18.27               29.4
2    CN   CHN   China 2005   5053.379 1303720000      12.40               14.0
3    CN   CHN   China 2000   2915.415 1262645000      14.03               21.2
4    CN   CHN   China 1991   1091.449 1150780000      19.68               29.7
5    CN   CHN   China 2013  12218.521 1357380000      12.08                6.3
6    CN   CHN   China 1999   2649.745 1252735000      14.64               22.2
               region              income gdp_using
1 East Asia & Pacific Upper middle income  1.468052
2 East Asia & Pacific Upper middle income  6.588191
3 East Asia & Pacific Upper middle income  3.681134
4 East Asia & Pacific Upper middle income  1.256017
5 East Asia & Pacific Upper middle income 16.585176
6 East Asia & Pacific Upper middle income  3.319429
ggplot(nations_new, aes( x = year, y = gdp_using, group = country, color = country)) + 
  geom_point() +
  geom_line() +
  labs(title = "China's Rise to Become the Largest Econonmy", x = "year", y = "GDP ($ trillion)") +
 scale_color_brewer(palette = "Set1")

nations_new1 <- nations |>
  group_by(year, region) |>
  summarise(gdp = sum(gdp_using, na.rm = TRUE))
`summarise()` has grouped output by 'year'. You can override using the
`.groups` argument.
head(nations_new1)
# A tibble: 6 × 3
# Groups:   year [1]
   year region                       gdp
  <int> <chr>                      <dbl>
1  1990 East Asia & Pacific         5.52
2  1990 Europe & Central Asia       9.36
3  1990 Latin America & Caribbean   2.40
4  1990 Middle East & North Africa  1.66
5  1990 North America               6.54
6  1990 South Asia                  1.35
ggplot(nations_new1, aes( x = year, y = gdp, group = region, fill = region)) +
  geom_area(color = "white") +
  labs( title = "GDP by World Bank Region", x = "year", y = "GDP ($trilion)")

  scale_fill_brewer(palette = "Set2") 
<ggproto object: Class ScaleDiscrete, Scale, gg>
    aesthetics: fill
    axis_order: function
    break_info: function
    break_positions: function
    breaks: waiver
    call: call
    clone: function
    dimension: function
    drop: TRUE
    expand: waiver
    fallback_palette: function
    get_breaks: function
    get_breaks_minor: function
    get_labels: function
    get_limits: function
    get_transformation: function
    guide: legend
    is_discrete: function
    is_empty: function
    labels: waiver
    limits: NULL
    make_sec_title: function
    make_title: function
    map: function
    map_df: function
    minor_breaks: waiver
    n.breaks.cache: NULL
    na.translate: TRUE
    na.value: NA
    name: waiver
    palette: function
    palette.cache: NULL
    position: left
    range: environment
    rescale: function
    reset: function
    train: function
    train_df: function
    transform: function
    transform_df: function
    super:  <ggproto object: Class ScaleDiscrete, Scale, gg>