Load the libraries and dataset
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.1 ✔ purrr 1.0.1
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.5.0
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
setwd("C:/Users/earlb/OneDrive/Documents/Data Science 110")
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.
install.packages("ggplot2")
## Warning: package 'ggplot2' is in use and will not be installed
library("RColorBrewer")
library("ggplot2")
Nations %>%
filter(country %in% c('Ghana', 'Togo' , 'Nigeria', 'Cameroon')) %>%
mutate (real_gdp = (gdp_percap * population)/10^12) %>%
ggplot(aes(x= year, y = real_gdp, fill=country)) +
geom_line(linetype = "dotted")+
geom_point() +
scale_colour_brewer(palette = "Set1")
ggtitle("West African Countries Population")
## $title
## [1] "West African Countries Population"
##
## attr(,"class")
## [1] "labels"
library("ggplot2")
Nations3 <- Nations %>%
mutate (real_gdp = (gdp_percap * population)/10^12) %>%
group_by(region , year) %>%
summarise(real_gdp = sum(real_gdp, na.rm = TRUE))
## `summarise()` has grouped output by 'region'. You can override using the
## `.groups` argument.
head(Nations3)
## # A tibble: 6 × 3
## # Groups: region [1]
## region year real_gdp
## <chr> <dbl> <dbl>
## 1 East Asia & Pacific 1990 5.52
## 2 East Asia & Pacific 1991 6.03
## 3 East Asia & Pacific 1992 6.50
## 4 East Asia & Pacific 1993 7.04
## 5 East Asia & Pacific 1994 7.64
## 6 East Asia & Pacific 1995 8.29
ggplot ( aes(x = year , y = real_gdp), data = Nations3) +
geom_area(na.rm = FALSE) +
scale_fill_brewer(palette = "Set2")
xlab("Year")
## $x
## [1] "Year"
##
## attr(,"class")
## [1] "labels"
ylab("Real GDP")
## $y
## [1] "Real GDP"
##
## attr(,"class")
## [1] "labels"
ggtitle("World Bank Region")
## $title
## [1] "World Bank Region"
##
## attr(,"class")
## [1] "labels"
Nations3 %>%
ggplot2::aes( x = year, y = real_gdp) %>%
geom_area() %>%
scale_fill_brewer(palette = "Set2")
## Warning in geom_area(.): Ignoring unknown aesthetics:
## <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
## get_breaks: function
## get_breaks_minor: function
## get_labels: function
## get_limits: 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
## n.breaks.cache: NULL
## na.translate: TRUE
## na.value: NA
## name: <ggproto object: Class LayerInstance, Layer, gg>
## aes_params: list
## compute_aesthetics: function
## compute_geom_1: function
## compute_geom_2: function
## compute_position: function
## compute_statistic: function
## computed_geom_params: NULL
## computed_mapping: NULL
## computed_stat_params: NULL
## constructor: call
## data: waiver
## draw_geom: function
## finish_statistics: function
## geom: <ggproto object: Class GeomArea, GeomRibbon, Geom, gg>
## aesthetics: function
## default_aes: uneval
## draw_group: function
## draw_key: function
## draw_layer: function
## draw_panel: function
## extra_params: na.rm orientation
## handle_na: function
## non_missing_aes:
## optional_aes:
## parameters: function
## rename_size: TRUE
## required_aes: x y
## setup_data: function
## setup_params: function
## use_defaults: function
## super: <ggproto object: Class GeomRibbon, Geom, gg>
## geom_params: list
## inherit.aes: TRUE
## layer_data: function
## map_statistic: function
## mapping: uneval
## position: <ggproto object: Class PositionStack, Position, gg>
## compute_layer: function
## compute_panel: function
## fill: FALSE
## required_aes:
## reverse: FALSE
## setup_data: function
## setup_params: function
## type: NULL
## vjust: 1
## super: <ggproto object: Class Position, gg>
## print: function
## setup_layer: function
## show.legend: NA
## stat: <ggproto object: Class StatAlign, Stat, gg>
## aesthetics: function
## compute_group: function
## compute_layer: function
## compute_panel: function
## default_aes: uneval
## dropped_aes:
## extra_params: na.rm orientation
## finish_layer: function
## non_missing_aes:
## optional_aes:
## parameters: function
## required_aes: x y
## retransform: TRUE
## setup_data: function
## setup_params: function
## super: <ggproto object: Class Stat, gg>
## stat_params: list
## super: <ggproto object: Class Layer, gg>
## palette: function
## palette.cache: NULL
## position: left
## range: <ggproto object: Class RangeDiscrete, Range, gg>
## range: NULL
## reset: function
## train: function
## super: <ggproto object: Class RangeDiscrete, Range, gg>
## rescale: function
## reset: function
## scale_name: brewer
## train: function
## train_df: function
## transform: function
## transform_df: function
## super: <ggproto object: Class ScaleDiscrete, Scale, gg>
ggtitle("Wt African Countries Population")
## $title
## [1] "Wt African Countries Population"
##
## attr(,"class")
## [1] "labels"