Ocultar código
library(glue)
library(ggtext)
library(showtext)
library(tidyverse)
Sitio en construcción
Víctor Gauto
11 de septiembre de 2025
Cantidad de países que pueden visitarse sin una visa previa, para portadores de pasaportes de una selección de países sudamericanos.
Colores.
Fuentes: Ubuntu y JetBrains Mono.
fuente <- glue(
"Datos: <span style='color:{c1};'><span style='font-family:jet;'>",
"{{<b>tidytuesdayR</b>}}</span> semana 36, ",
"<b>Henley Passport Index</b>.</span>"
)
autor <- glue("<span style='color:{c1};'>**Víctor Gauto**</span>")
icon_twitter <- glue("<span style='font-family:jet;'></span>")
icon_instagram <- glue("<span style='font-family:jet;'></span>")
icon_github <- glue("<span style='font-family:jet;'></span>")
icon_mastodon <- glue("<span style='font-family:jet;'>󰫑</span>")
icon_bsky <- glue("<span style='font-family:jet;'></span>")
usuario <- glue("<span style='color:{c1};'>**vhgauto**</span>")
sep <- glue("**|**")
mi_caption <- glue(
"{fuente}<br>{autor} {sep} {icon_github} {icon_twitter} {icon_instagram} ",
"{icon_mastodon} {icon_bsky} {usuario}"
)
Me interesa la cantidad de países que se pueden visitar con cada pasaporte.
Selección de países sudamericanos y paleta de colores.
Filtro los datos, aplico colores y genero factores, considerando la traducción de Brasil.
d <- rank_by_year |>
filter(country %in% paises) |>
filter(visa_free_count != 0) |>
mutate(id = map_dbl(.x = country, ~ which(.x == paises))) |>
mutate(color = colores[id]) |>
mutate(
label = glue("<b style='color: {color}'>{country}</b>")
) |>
arrange(country, year) |>
mutate(label = str_replace(label, "Brazil", "Brasil")) |>
mutate(label = fct_inorder(label))
Obtengo los valores para los años extremos y aplico espaciado a las etiquetas.
Título y figura.
mi_titulo <- glue(
"Evolución de la cantidad de países que se pueden visitar **SIN** una",
"<span style='color: {colores[1]}'>*visa*</span> previa para una selección",
"de <b style='color: {colores[8]}'>países sudamericanos</b>",
.sep = " "
)
g <- ggplot(d, aes(year, visa_free_count, color = country)) +
geom_label(
data = d_min_max,
aes(year, visa_free_count, label = visa_free_count, hjust = hjust),
family = "jet",
fill = c6,
label.size = unit(0, "pt"),
label.r = unit(0, "pt"),
label.padding = unit(2, "pt"),
fontface = "bold"
) +
ggbump::geom_bump(linewidth = 3, lineend = "round") +
ggbump::geom_bump(
data = select(d, -label),
aes(year, visa_free_count, group = country),
inherit.aes = FALSE,
linewidth = 1,
alpha = .2,
lineend = "round",
color = c5
) +
ggbump::geom_bump(
aes(group = country),
linewidth = .7,
lineend = "round",
color = c7
) +
facet_wrap(vars(label), ncol = 3, scales = "fixed", axes = "margins") +
scale_color_manual(
breaks = paises,
values = colores
) +
scale_y_continuous(breaks = scales::breaks_width(50)) +
coord_cartesian(clip = "off") +
labs(y = NULL, x = NULL, title = mi_titulo, caption = mi_caption) +
theme_void(base_size = 12, base_family = "ubuntu") +
theme(
aspect.ratio = 1,
plot.background = element_rect(fill = c7, color = NA),
plot.margin = margin(t = 10, b = 7, r = 13, l = 10),
plot.title = element_textbox_simple(
size = rel(1.7),
margin = margin(b = 8)
),
plot.caption = element_markdown(
color = c2,
size = rel(1.1),
lineheight = 1.1,
margin = margin(t = 13)
),
legend.position = "none",
axis.text.x = element_text(
family = "jet",
size = rel(1.1),
color = c4,
margin = margin(t = 3)
),
axis.text.y = element_text(
family = "jet",
color = c5,
size = rel(.9),
hjust = 1,
angle = 90
),
panel.background = element_rect(fill = c6, color = NA),
panel.grid.major = element_line(
color = c5,
linewidth = .1,
linetype = "FF"
),
panel.spacing.x = unit(25, "pt"),
panel.spacing.y = unit(10, "pt"),
strip.text = element_markdown(
hjust = 0,
fill = c7,
padding = unit(c(3, 3, 3, 3), "pt"),
size = rel(1.7),
margin = margin(b = -30)
),
strip.background = element_blank()
)
Guardo.
---
format:
html:
code-fold: show
code-summary: "Ocultar código"
code-line-numbers: false
code-annotations: false
code-link: true
code-tools:
source: true
toggle: true
caption: "Código"
code-overflow: scroll
page-layout: full
editor_options:
chunk_output_type: console
categories:
- geom_label
- geom_bump
execute:
eval: false
echo: true
warning: false
title: "Semana 36"
date: last-modified
author: Víctor Gauto
---
Cantidad de países que pueden visitarse sin una visa previa, para portadores de pasaportes de una selección de países sudamericanos.
::: {.column-page-right}

:::
## Paquetes
```{r}
library(glue)
library(ggtext)
library(showtext)
library(tidyverse)
```
## Estilos
Colores.
```{r}
c1 <- "#48171C"
c2 <- "#004042"
c3 <- "white"
c4 <- "black"
c5 <- "grey60"
c6 <- "grey90"
c7 <- "grey95"
```
Fuentes: Ubuntu y JetBrains Mono.
```{r}
font_add(
family = "ubuntu",
regular = "././fuente/Ubuntu-Regular.ttf",
bold = "././fuente/Ubuntu-Bold.ttf",
italic = "././fuente/Ubuntu-Italic.ttf"
)
font_add(
family = "jet",
regular = "././fuente/JetBrainsMonoNLNerdFontMono-Regular.ttf"
)
showtext_auto()
showtext_opts(dpi = 300)
```
## Epígrafe
```{r}
fuente <- glue(
"Datos: <span style='color:{c1};'><span style='font-family:jet;'>",
"{{<b>tidytuesdayR</b>}}</span> semana 36, ",
"<b>Henley Passport Index</b>.</span>"
)
autor <- glue("<span style='color:{c1};'>**Víctor Gauto**</span>")
icon_twitter <- glue("<span style='font-family:jet;'></span>")
icon_instagram <- glue("<span style='font-family:jet;'></span>")
icon_github <- glue("<span style='font-family:jet;'></span>")
icon_mastodon <- glue("<span style='font-family:jet;'>󰫑</span>")
icon_bsky <- glue("<span style='font-family:jet;'></span>")
usuario <- glue("<span style='color:{c1};'>**vhgauto**</span>")
sep <- glue("**|**")
mi_caption <- glue(
"{fuente}<br>{autor} {sep} {icon_github} {icon_twitter} {icon_instagram} ",
"{icon_mastodon} {icon_bsky} {usuario}"
)
```
## Datos
```{r}
tuesdata <- tidytuesdayR::tt_load(2025, 36)
rank_by_year <- tuesdata$rank_by_year
```
## Procesamiento
Me interesa la cantidad de países que se pueden visitar con cada pasaporte.
Selección de países sudamericanos y paleta de colores.
```{r}
paises <- c(
"Argentina",
"Chile",
"Brazil",
"Uruguay",
"Bolivia",
"Venezuela",
"Colombia",
"Paraguay",
"Ecuador"
)
colores <- c(
MoMAColors::moma.colors(palette_name = "Abbott"),
c1
)
```
Filtro los datos, aplico colores y genero factores, considerando la traducción de Brasil.
```{r}
d <- rank_by_year |>
filter(country %in% paises) |>
filter(visa_free_count != 0) |>
mutate(id = map_dbl(.x = country, ~ which(.x == paises))) |>
mutate(color = colores[id]) |>
mutate(
label = glue("<b style='color: {color}'>{country}</b>")
) |>
arrange(country, year) |>
mutate(label = str_replace(label, "Brazil", "Brasil")) |>
mutate(label = fct_inorder(label))
```
Obtengo los valores para los años extremos y aplico espaciado a las etiquetas.
```{r}
espacio <- 5
d_min <- slice_min(d, order_by = year, n = 1)
d_max <- slice_max(d, order_by = year, n = 1)
d_min_max <- rbind(d_min, d_max) |>
mutate(
visa_free_count = if_else(
year == 2006,
visa_free_count + espacio,
visa_free_count - espacio
)
) |>
mutate(hjust = if_else(year == 2006, 1, 0))
```
## Figura
Título y figura.
```{r}
mi_titulo <- glue(
"Evolución de la cantidad de países que se pueden visitar **SIN** una",
"<span style='color: {colores[1]}'>*visa*</span> previa para una selección",
"de <b style='color: {colores[8]}'>países sudamericanos</b>",
.sep = " "
)
g <- ggplot(d, aes(year, visa_free_count, color = country)) +
geom_label(
data = d_min_max,
aes(year, visa_free_count, label = visa_free_count, hjust = hjust),
family = "jet",
fill = c6,
label.size = unit(0, "pt"),
label.r = unit(0, "pt"),
label.padding = unit(2, "pt"),
fontface = "bold"
) +
ggbump::geom_bump(linewidth = 3, lineend = "round") +
ggbump::geom_bump(
data = select(d, -label),
aes(year, visa_free_count, group = country),
inherit.aes = FALSE,
linewidth = 1,
alpha = .2,
lineend = "round",
color = c5
) +
ggbump::geom_bump(
aes(group = country),
linewidth = .7,
lineend = "round",
color = c7
) +
facet_wrap(vars(label), ncol = 3, scales = "fixed", axes = "margins") +
scale_color_manual(
breaks = paises,
values = colores
) +
scale_y_continuous(breaks = scales::breaks_width(50)) +
coord_cartesian(clip = "off") +
labs(y = NULL, x = NULL, title = mi_titulo, caption = mi_caption) +
theme_void(base_size = 12, base_family = "ubuntu") +
theme(
aspect.ratio = 1,
plot.background = element_rect(fill = c7, color = NA),
plot.margin = margin(t = 10, b = 7, r = 13, l = 10),
plot.title = element_textbox_simple(
size = rel(1.7),
margin = margin(b = 8)
),
plot.caption = element_markdown(
color = c2,
size = rel(1.1),
lineheight = 1.1,
margin = margin(t = 13)
),
legend.position = "none",
axis.text.x = element_text(
family = "jet",
size = rel(1.1),
color = c4,
margin = margin(t = 3)
),
axis.text.y = element_text(
family = "jet",
color = c5,
size = rel(.9),
hjust = 1,
angle = 90
),
panel.background = element_rect(fill = c6, color = NA),
panel.grid.major = element_line(
color = c5,
linewidth = .1,
linetype = "FF"
),
panel.spacing.x = unit(25, "pt"),
panel.spacing.y = unit(10, "pt"),
strip.text = element_markdown(
hjust = 0,
fill = c7,
padding = unit(c(3, 3, 3, 3), "pt"),
size = rel(1.7),
margin = margin(b = -30)
),
strip.background = element_blank()
)
```
Guardo.
```{r}
ggsave(
plot = g,
filename = "tidytuesday/2025/semana_36.png",
width = 30,
height = 33,
units = "cm"
)
```