Ocultar código
library(glue)
library(ggtext)
library(showtext)
library(grid)
library(tidyverse)
Sitio en construcción
Víctor Gauto
6 de octubre de 2025
Países con la mayor cantidad de Grandes Maestros de ajedrez.
Colores.
Fuentes: Ubuntu y JetBrains Mono.
fuente <- glue(
"Datos: <span style='color:{c3};'><span style='font-family:jet;'>",
"{{<b>tidytuesdayR</b>}}</span> semana 38, ",
"<b>International Chess Federation</b>.</span>"
)
autor <- glue("<span style='color:{c3};'>**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:{c3};'>**vhgauto**</span>")
sep <- glue("**|**")
mi_caption <- glue(
"{fuente}<br>{autor} {sep} {icon_github} {icon_twitter} {icon_instagram} ",
"{icon_mastodon} {icon_bsky} {usuario}"
)
Me interesan los países con mayor cantidad de Grandes Maestros.
Obtengo los nombres de los países de acuerdo con la abreviatura de sus federaciones.
Selecciono septiembre de 2025 como el mes de interés y creo datos con las traducciones de los países.
d <- inner_join(september, fed_tbl, by = join_by(fed)) |>
filter(title %in% c("GM", "FGM")) |>
count(country, sort = TRUE) |>
mutate(country = fct_reorder(country, n)) |>
slice_max(order_by = country, n = 12)
country_tbl <- tibble(
country = d$country,
pais = c(
"Alemania",
"EE.UU.",
"India",
"Rusia",
"Ucrania",
"Francia",
"Serbia",
"España",
"Israel",
"Polonia",
"Hungría",
"China"
)
)
Combino todos los datos.
Defino patrones para las barras usando {grid}
y diferentes intensidades de colores.
f_pattern <- function(C) {
pattern(
gTree(
children = gList(
rectGrob(
x = c(.25, .75),
y = c(.25, .75),
width = .5,
height = .5,
gp = gpar(fill = scales::col_darker(C), col = NA)
),
rectGrob(
x = c(.25, .75),
y = c(.75, .25),
width = .5,
height = .5,
gp = gpar(fill = scales::col_lighter(C), col = NA)
)
)
),
width = .05,
height = .05,
extend = "repeat"
)
}
p <- map(
scico::scico(n = 12, palette = "bam"),
f_pattern
)
Título y figura.
mi_titulo <- glue(
"Países con mayor cantidad de <b style='color: {c3};'>Grandes Maestros</b> ",
" del<br><b style='color: {c4};'>ajedrez</b>, masculinos y femeninos, a ",
"septiembre de 2025"
)
g <- ggplot(d2, aes(n, pais, fill = pais)) +
geom_col(show.legend = FALSE, width = .8, fill = p) +
scale_x_continuous(breaks = scales::breaks_width(10)) +
coord_cartesian(expand = FALSE) +
labs(x = NULL, y = NULL, title = mi_titulo, caption = mi_caption) +
theme_bw(base_size = 24, base_family = "ubuntu") +
theme(
text = element_text(color = c2),
aspect.ratio = 1,
axis.ticks.y = element_blank(),
axis.ticks.x = element_line(color = c2, linewidth = .2),
panel.border = element_blank(),
panel.background = element_blank(),
panel.grid = element_blank(),
panel.grid.major.x = element_line(
color = c2,
linewidth = .1,
linetype = "55"
),
panel.ontop = TRUE,
axis.text = element_text(color = c2),
axis.text.x = element_text(family = "jet"),
axis.text.y = element_text(margin = margin(r = 15)),
plot.background = element_rect(fill = c1, color = NA),
plot.title = element_markdown(lineheight = 1.2),
plot.title.position = "plot",
plot.caption = element_markdown(
size = rel(.6),
lineheight = 1.2,
color = c4
)
)
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_col
- geom_col
execute:
eval: false
echo: true
warning: false
title: "Semana 38"
date: last-modified
author: Víctor Gauto
---
Países con la mayor cantidad de Grandes Maestros de ajedrez.
::: {.column-page-right}

:::
## Paquetes
```{r}
library(glue)
library(ggtext)
library(showtext)
library(grid)
library(tidyverse)
```
## Estilos
Colores.
```{r}
c1 <- "black"
c2 <- "white"
c3 <- "#BA5AA2"
c4 <- "#659643"
```
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:{c3};'><span style='font-family:jet;'>",
"{{<b>tidytuesdayR</b>}}</span> semana 38, ",
"<b>International Chess Federation</b>.</span>"
)
autor <- glue("<span style='color:{c3};'>**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:{c3};'>**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, 38)
september <- tuesdata$fide_ratings_september
```
## Procesamiento
Me interesan los países con mayor cantidad de [Grandes Maestros](https://es.wikipedia.org/wiki/Gran_maestro_internacional).
Obtengo los nombres de los países de acuerdo con la abreviatura de sus [federaciones](https://www.mark-weeks.com/aboutcom/mw15b16.htm).
```{r}
fed_tbl <- rvest::read_html(
"https://www.mark-weeks.com/aboutcom/mw15b16.htm"
) |>
rvest::html_table() |>
pluck(2) |>
rename_with(tolower) |>
select(fed, country)
```
Selecciono septiembre de 2025 como el mes de interés y creo datos con las traducciones de los países.
```{r}
d <- inner_join(september, fed_tbl, by = join_by(fed)) |>
filter(title %in% c("GM", "FGM")) |>
count(country, sort = TRUE) |>
mutate(country = fct_reorder(country, n)) |>
slice_max(order_by = country, n = 12)
country_tbl <- tibble(
country = d$country,
pais = c(
"Alemania",
"EE.UU.",
"India",
"Rusia",
"Ucrania",
"Francia",
"Serbia",
"España",
"Israel",
"Polonia",
"Hungría",
"China"
)
)
```
Combino todos los datos.
```{r}
d2 <- inner_join(country_tbl, d, by = join_by(country)) |>
mutate(pais = factor(pais, levels = rev(pais)))
```
## Figura
Defino [patrones](https://www.tidyverse.org/blog/2024/02/ggplot2-3-5-0/#patterns-and-gradients) para las barras usando `{grid}` y diferentes intensidades de colores.
```{r}
f_pattern <- function(C) {
pattern(
gTree(
children = gList(
rectGrob(
x = c(.25, .75),
y = c(.25, .75),
width = .5,
height = .5,
gp = gpar(fill = scales::col_darker(C), col = NA)
),
rectGrob(
x = c(.25, .75),
y = c(.75, .25),
width = .5,
height = .5,
gp = gpar(fill = scales::col_lighter(C), col = NA)
)
)
),
width = .05,
height = .05,
extend = "repeat"
)
}
p <- map(
scico::scico(n = 12, palette = "bam"),
f_pattern
)
```
Título y figura.
```{r}
mi_titulo <- glue(
"Países con mayor cantidad de <b style='color: {c3};'>Grandes Maestros</b> ",
" del<br><b style='color: {c4};'>ajedrez</b>, masculinos y femeninos, a ",
"septiembre de 2025"
)
g <- ggplot(d2, aes(n, pais, fill = pais)) +
geom_col(show.legend = FALSE, width = .8, fill = p) +
scale_x_continuous(breaks = scales::breaks_width(10)) +
coord_cartesian(expand = FALSE) +
labs(x = NULL, y = NULL, title = mi_titulo, caption = mi_caption) +
theme_bw(base_size = 24, base_family = "ubuntu") +
theme(
text = element_text(color = c2),
aspect.ratio = 1,
axis.ticks.y = element_blank(),
axis.ticks.x = element_line(color = c2, linewidth = .2),
panel.border = element_blank(),
panel.background = element_blank(),
panel.grid = element_blank(),
panel.grid.major.x = element_line(
color = c2,
linewidth = .1,
linetype = "55"
),
panel.ontop = TRUE,
axis.text = element_text(color = c2),
axis.text.x = element_text(family = "jet"),
axis.text.y = element_text(margin = margin(r = 15)),
plot.background = element_rect(fill = c1, color = NA),
plot.title = element_markdown(lineheight = 1.2),
plot.title.position = "plot",
plot.caption = element_markdown(
size = rel(.6),
lineheight = 1.2,
color = c4
)
)
```
Guardo.
```{r}
ggsave(
plot = g,
filename = "tidytuesday/2025/semana_38.png",
width = 30,
height = 30,
units = "cm"
)
```
```{r}
#| eval: false
#| echo: false
piezas <- c(
"\U265A",
"\U265B",
"\U265C",
"\U265D",
"\U265E",
"\U265F"
)
piezas_blancas <- glue("<span style='color: white;'>{piezas}</span>")
piezas_oscuras <- glue("<span style='color: black;'>{piezas}</span>")
ancho <- ceiling(max(d$n) / 2)
alto <- nrow(d) * 3 - 1
d_tablero <- expand_grid(
y = 1:alto,
x = 1:ancho
) |>
mutate(id = row_number()) |>
mutate(fill = if_else(id %% 2 == 0, c2, c1)) |>
select(-id)
d_country <- d |>
arrange(country) |>
mutate(id = row_number()) |>
mutate(y = lag(x = id, n = 2, default = 0)) |>
mutate(y = id * 2 + y) |>
mutate(y = if_else(id == 1, 1, y)) |>
mutate(y = y + 1) |>
inner_join(country_tbl, by = join_by(country)) |>
mutate(pais = fct_reorder(pais, n))
d_y1 <- d |>
arrange(country) |>
mutate(id = row_number()) |>
mutate(y = lag(x = id, n = 2, default = 0)) |>
mutate(y = id * 2 + y) |>
mutate(y = if_else(id == 1, 1, y)) |>
mutate(y = y + 1) |>
mutate(x = map(ceiling(n / 2), ~ 1:.x)) |>
mutate(largo = map_dbl(x, length)) |>
mutate(blancas = c(piezas_blancas, piezas_blancas)) |>
mutate(oscuras = c(piezas_oscuras, piezas_oscuras)) |>
unnest(x) |>
inner_join(d_tablero, by = join_by(x, y)) |>
mutate(label = if_else(fill == c2, oscuras, blancas))
d_y2 <- d |>
arrange(country) |>
mutate(id = row_number()) |>
mutate(y = lag(x = id, n = 2, default = 0)) |>
mutate(y = id * 2 + y) |>
mutate(y = if_else(id == 1, 1, y)) |>
mutate(x = map(n - ceiling(n / 2), ~ 1:.x)) |>
mutate(largo = map_dbl(x, length)) |>
mutate(blancas = c(piezas_blancas, piezas_blancas)) |>
mutate(oscuras = c(piezas_oscuras, piezas_oscuras)) |>
unnest(x) |>
inner_join(d_tablero, by = join_by(x, y)) |>
mutate(label = if_else(fill == c2, oscuras, blancas))
d_y <- rbind(d_y1, d_y2)
g <- ggplot(d_tablero, aes(x, y, fill = fill)) +
geom_tile() +
geom_richtext(
data = d_y,
aes(x + .1, y, label = label),
inherit.aes = FALSE,
size = 5,
fill = NA,
label.color = NA
) +
geom_text(
data = d_country,
aes(0, y - .5, label = pais),
inherit.aes = FALSE,
family = "ubuntu",
color = c2,
size = 6,
hjust = 1
) +
geom_point(
data = d_country,
aes(ceiling(n / 2) + 1.5, y - .5),
inherit.aes = FALSE,
shape = 21,
size = 8,
color = c1,
fill = c2,
stroke = .4
) +
geom_text(
data = d_country,
aes(ceiling(n / 2) + 1.5, y - .5, label = n),
inherit.aes = FALSE,
family = "jet",
size = 4,
color = c1
) +
scale_x_continuous(breaks = scales::breaks_width(1)) +
scale_y_continuous(breaks = scales::breaks_width(1)) +
scale_fill_identity() +
coord_equal(clip = "off", xlim = c(-3, NA)) +
theme_void(base_family = "ubuntu") +
theme(
plot.background = element_rect(fill = c1)
)
ggsave(
plot = g,
filename = "tidytuesday/2025/semana_38.png",
width = 30,
height = 25,
units = "cm"
)
browseURL(paste0(getwd(), "/tidytuesday/2025/semana_38_XXX.png"))
```