::shelf(
librarian
tidyverse
, tidytuesdayR
, sf
, maps
, sysfonts
)
font_add_google("Quicksand")
font_add_google("Fira Sans")
::showtext_auto()
showtext
<- "Quicksand"
f1 <- "Fira Sans"
f2
<- tt_load("2022-02-22")
data
<-
freedom $freedom |>
data::clean_names()# |> janitor
Day 06 - 08
R
Data Viz
sf
ggplot2
Day 6 - 8 from #30 Day Map Challenge
Code
|>
freedom count(region_name) #americas
<-
freedom_lt |>
freedom filter(
== "Americas"
region_name !(str_detect(country, "America|Canada"))
, |>
) mutate(
country =
case_when(
str_detect(country, "Bolivia") ~ "Bolivia"
str_detect(country, "Venez") ~ "Venezuela"
, ~ country
, T
)status =
, ifelse(status == "F", "Libre", ifelse(status == "NF", "No Libre", "Parcialmente Libre")) |>
factor(c("Libre", "Parcialmente Libre", "No Libre"))
)
<-
world map_data("world") |>
as_tibble() |>
rename(country = region)
<-
latam right_join(world, freedom_lt) #|>
<- unique(latam$year)
anios
<- c("#006f3c", "#264b96", "#bf212f") libre
::saveGIF(
animation
{::walk(anios, function(y, latam){
purrr::cli_process_start("Compute {.val {y}}")
cli<- latam |>
p ::filter(year == y) |>
dplyrggplot() +
aes(long, lat, group = paste(country, group), fill = status) +
geom_polygon(color = "gray80", size = .25) +
coord_fixed() +
scale_fill_manual(values = libre) +
labs(
title = glue::glue("{y} - Libertad en Latinomerica")
subtitle = "Función de las libertades civiles y derechos políticos"
, caption = "\n#30DayMapChallenge | Día 5, 6 y 7: Red, Green, Blue\nCreado por @JhonKevinFlore1\nData: Freedom House a travéz de Arthur Cheiv\n#TidyTuesday 2022/08\n"
, fill = ""
, +
) guides(
fill = guide_legend(
direction = "horizontal"
title.position = "top"
, title.hjust = .5
, label.hjust = .5
, label.position = "bottom"
, keywidth = 2
, keyheight = .4
,
)+
) theme_void() +
# hrbrthemes::theme_ft_rc(grid = FALSE, axis_text_size = 0) +
theme(
legend.position = c(.3, .35)
legend.text = element_text(size = 20, family = f2)
, plot.title = element_text(hjus = .5, family = f2, size = 40, face = "bold")
, plot.subtitle = element_text(size = 30, hjust = .5, family = f2)
, plot.caption = element_text(size = 15, lineheight = .3, hjust = 1, vjust = .5, family = f1)
, plot.caption.position = 'panel'
,
)plot(p)
::cli_process_done()
clilatam = latam)
},
},movie.name = here::here("plots", "day6-8.gif")
interval = 1
, ani.width = 1385
, ani.height = 1500
, ani.res = 300
, )