nationsdatasethw

Author

Tikki Dibonge

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   3.5.2     ✔ 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("~/Downloads/DATA110")
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.
nations_gdp <- nations |>
  mutate(gdp_trillions = gdp_percap * population / 10^12)
gdp_trillions_4 <- nations_gdp |>
  filter(country == "Brazil" | country == "Portugal" | country == "Sweden" | country == "South Africa")
p1 <- gdp_trillions_4 |> ggplot() +
          geom_point(aes(x = year, y = gdp_trillions, color = country)) +       
  scale_color_brewer(palette = "Set1") +
          geom_line(aes(x = year, y = gdp_trillions, color = country)) +
  labs(title = "GDP of Brazil, Portugal, South Africa, and Sweden", 
       x = "Year",
       y = "GDP in Trillions",
       caption = "Citations: https://ggplot2-book.org/themes.html, https://www.statology.org/hjust-vjust-ggplot2/",
      color = "Country") +
  theme_classic(base_size = 12) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(1, 1)) 
Warning: A numeric `legend.position` argument in `theme()` was deprecated in ggplot2
3.5.0.
ℹ Please use the `legend.position.inside` argument of `theme()` instead.
p1

library(tidyverse)
library(RColorBrewer)
library(scales)

Attaching package: 'scales'
The following object is masked from 'package:purrr':

    discard
The following object is masked from 'package:readr':

    col_factor
setwd("~/Downloads/DATA110")
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.
nations <- nations |>
  mutate(gdp_trillions = (gdp_percap * population / 10^12))
region_gdp <- nations |>
group_by(region, year) |>
  summarize(gdp=sum(gdp_trillions, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
p2 <- region_gdp |> 
  ggplot(aes(x = year, y = gdp, fill = region)) +
  geom_area(color = "white", size = 0.1) +
  scale_fill_brewer(palette = "Set2") +
  labs(title = "GDP of Regions in Trillions",
       x = "Year",
       y = "GDP in Trillions",
       fill = "Region") +
  theme_minimal(base_size = 14) +
  theme(legend.position = c(1,1)) +
  theme(plot.title = element_text(hjust = 0.5)) 
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
p2