library(tidyverse) # ggplot, lubridate, dplyr, stringr, readr...
library(maps)
library(praise)
CIA Factbook
The Data
This week we’re exploring the CIA World Factbook! The dataset this week comes from the CIA Factbook, Country Comparisons, 2014, via the {openintro} R package, via the {usdatasets} R package, via this post on LinkedIn.
The World Factbook provides basic intelligence on the history, people, government, economy, energy, geography, environment, communications, transportation, military, terrorism, and transnational issues for 265 world entities.
<- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2024/2024-10-22/cia_factbook.csv') |>
cia mutate(iso_a3 = countrycode::countrycode(
country,origin = "country.name",
destination = "iso3c"
|>
)) drop_na(iso_a3)
World Map
<- map_data("world") |> # ggplot2
world_data mutate(iso_a3 = countrycode::countrycode(
region,origin = "country.name",
destination = "iso3c"
|>
)) drop_na(iso_a3)
<- world_data |>
data4map left_join(cia, by = "iso_a3")
|>
data4map ggplot(aes(x = long, y = lat, group = group)) +
geom_polygon(aes(fill = death_rate), color = "black", size = 0.15) +
theme_void() +
scale_fill_gradient(trans = "log")
#scale_fill_gradient(low = "blue", high = "purple")
Shiny App
I also created a Shiny App which allows the user to change the variable that colors each country. However, I don’t have an obvious place to host the Shiny App. The source code for the Shiny App is in app.R
which is located at https://github.com/hardin47/TidyTuesday/tree/gh-pages/2024-10-22/CIAFactbook .
praise()
[1] "You are groovy!"