Gif_Project 3

Author

Jonathan RH

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.4     
── 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(gganimate)
library(gifski)
library(plotly)

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout
WBDI <- read_csv("world_bank_development_indicators.csv")
Rows: 17272 Columns: 50
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr   (1): country
dbl  (48): agricultural_land%, forest_land%, land_area, avg_precipitation, t...
date  (1): date

ℹ 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.
colnames(WBDI)[3] <- 'agrucultural_land_percentage'
colnames(WBDI)[4] <- 'forest_land_percentage'
head(WBDI)
# A tibble: 6 × 50
  country     date       agrucultural_land_pe…¹ forest_land_percentage land_area
  <chr>       <date>                      <dbl>                  <dbl>     <dbl>
1 Afghanistan 1960-01-01                   NA                       NA        NA
2 Afghanistan 1961-01-01                   57.9                     NA    652230
3 Afghanistan 1962-01-01                   58.0                     NA    652230
4 Afghanistan 1963-01-01                   58.0                     NA    652230
5 Afghanistan 1964-01-01                   58.1                     NA    652230
6 Afghanistan 1965-01-01                   58.1                     NA    652230
# ℹ abbreviated name: ¹​agrucultural_land_percentage
# ℹ 45 more variables: avg_precipitation <dbl>, `trade_in_services%` <dbl>,
#   control_of_corruption_estimate <dbl>, control_of_corruption_std <dbl>,
#   `access_to_electricity%` <dbl>, `renewvable_energy_consumption%` <dbl>,
#   electric_power_consumption <dbl>, CO2_emisions <dbl>,
#   other_greenhouse_emisions <dbl>, population_density <dbl>,
#   `inflation_annual%` <dbl>, real_interest_rate <dbl>, …
V_Countries <- WBDI |>
  filter(country %in% c("Brazil", "Argentina", "Colombia", "Peru", "Mexico", "United States")) |>
  filter(!is.na(political_stability_estimate)) |>
  mutate(GDP_Per_capita = GDP_current_US/population) |>
  mutate(Pop_M = population/1000000)
V_Countries$year <- format(V_Countries$date, "%Y")
V_Countries$year <-as.numeric(as.character(V_Countries$year))
Land_CO <- V_Countries |>
  ggplot(aes(x = GDP_Per_capita, y = Pop_M, color = country, size = political_stability_estimate)) +
  geom_point() +
  scale_x_log10()+
   labs(title = 'Visualizing Global Trends: US vs Latin Countries  Year: {frame_time}', 
       x = 'GDP per Capita', 
       y = 'Population (In Millions)',
       color = "Countries",
       size = "Political Stability",
       caption = "Source: World Bank Database") +
  transition_time(date) +
  ease_aes('linear') +
  theme(plot.title=element_text(size= 9))+
  theme_bw() +
  scale_color_manual(values = c("United States" = '#68228B',
  "Mexico" = '#EE2C2C',
  "Brazil" = '#76EE00',
  "Peru" = '#EE1289',
  "Colombia" = '#EE1',
  "Argentina" = '#00688B'))


#animation <- animate(Land_CO, height = 450, fps = 9, resolution = 1500, renderer = gifski_renderer())
#animation
#anim_save("Land_CO_Animated_Bubble_Chart.gif", animation = animation)