Víctor Gauto
  • Tidytuesday
  • Publicaciones
  • Mapas de Argentina
  • Visualizaciones
  • Mi CV
  1. 2025
  2. Semana 37

Sitio en construcción

  • Inicio
  • 2025
    • Semana 02
    • Semana 03
    • Semana 04
    • Semana 05
    • Semana 06
    • Semana 07
    • Semana 08
    • Semana 09
    • Semana 10
    • Semana 11
    • Semana 12
    • Semana 13
    • Semana 14
    • Semana 15
    • Semana 16
    • Semana 17
    • Semana 18
    • Semana 19
    • Semana 20
    • Semana 21
    • Semana 22
    • Semana 23
    • Semana 24
    • Semana 25
    • Semana 26
    • Semana 27
    • Semana 28
    • Semana 29
    • Semana 30
    • Semana 31
    • Semana 32
    • Semana 33
    • Semana 34
    • Semana 35
    • Semana 36
    • Semana 37
  • 2024
    • Semana 02
    • Semana 03
    • Semana 04
    • Semana 05
    • Semana 06
    • Semana 07
    • Semana 08
    • Semana 09
    • Semana 10
    • Semana 11
    • Semana 12
    • Semana 13
    • Semana 14
    • Semana 15
    • Semana 16
    • Semana 17
    • Semana 18
    • Semana 19
    • Semana 20
    • Semana 21
    • Semana 22
    • Semana 23
    • Semana 24
    • Semana 25
    • Semana 26
    • Semana 27
    • Semana 28
    • Semana 29
    • Semana 30
    • Semana 31
    • Semana 32
    • Semana 33
    • Semana 34
    • Semana 35
    • Semana 36
    • Semana 37
    • Semana 38
    • Semana 39
    • Semana 40
    • Semana 41
    • Semana 42
    • Semana 43
    • Semana 44
    • Semana 45
    • Semana 46
    • Semana 47
    • Semana 48
    • Semana 49
    • Semana 50
    • Semana 51
    • Semana 52
    • Semana 53
  • 2023
    • Semana 07
    • Semana 12
    • Semana 13
    • Semana 14
    • Semana 15
    • Semana 16
    • Semana 17
    • Semana 18
    • Semana 19
    • Semana 20
    • Semana 21
    • Semana 22
    • Semana 23
    • Semana 24
    • Semana 25
    • Semana 26
    • Semana 27
    • Semana 28
    • Semana 29
    • Semana 30
    • Semana 31
    • Semana 32
    • Semana 33
    • Semana 34
    • Semana 35
    • Semana 36
    • Semana 37
    • Semana 38
    • Semana 39
    • Semana 40
    • Semana 41
    • Semana 42
    • Semana 43
    • Semana 44
    • Semana 45
    • Semana 46
    • Semana 47
    • Semana 48
    • Semana 49
    • Semana 50
    • Semana 51
    • Semana 52

Contenido

  • Paquetes
  • Estilos
  • Epígrafe
  • Datos
  • Procesamiento
  • Figura
  • Editar esta página
  • Informar sobre problema
  1. 2025
  2. Semana 37

Semana 37

  • Mostrar todo el código
  • Ocultar todo el código

  • Ver el código fuente
geom_boxplot
Autor

Víctor Gauto

Fecha de publicación

23 de septiembre de 2025

Cantidad de nutrientes en platos de cinco países.

Semana 37, 2025

Paquetes

Ocultar código
library(glue)
library(ggtext)
library(showtext)
library(tidyverse)

Estilos

Colores.

Ocultar código
c1 <- "#D8DEE9"
c2 <- "#2E3440"
c3 <- "#3B4252"
c4 <- "#434C5E"
c5 <- "white"
c6 <- "#74ACDF"

Fuentes: Ubuntu y JetBrains Mono.

Ocultar código
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

Ocultar código
fuente <- glue(
  "Datos: <span style='color:{c1};'><span style='font-family:jet;'>",
  "{{<b>tidytuesdayR</b>}}</span> semana 37, ",
  "<b>{{tastyR}}, allrecipes.com</b></span>"
)

autor <- glue("<span style='color:{c1};'>**Víctor Gauto**</span>")
icon_twitter <- glue("<span style='font-family:jet;'>&#xf099;</span>")
icon_instagram <- glue("<span style='font-family:jet;'>&#xf16d;</span>")
icon_github <- glue("<span style='font-family:jet;'>&#xf09b;</span>")
icon_mastodon <- glue("<span style='font-family:jet;'>&#xf0ad1;</span>")
icon_bsky <- glue("<span style='font-family:jet;'>&#xe28e;</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

Ocultar código
tuesdata <- tidytuesdayR::tt_load(2025, 37)
cuisines <- tuesdata$cuisines

Procesamiento

Me interesa la distribución de la cantidad de nutrientes (lípidos, carbohidratos y proteínas) en cinco países (Argentina, Grecia, Italia, Japón y España).

Creo etiquetas para nutrientes y países.

Ocultar código
nut_tbl <- tibble(
  nut = c("fat", "carbs", "protein"),
  nut_trad = c(
    "Lípidos (g/porción)",
    "Carbohidratos (g/porción)",
    "Proteínas (g/porción)"
  )
)

country_tbl <- tibble(
  country = c("argentinian", "greek", "italian", "japanese", "spanish"),
  pais = c("Argentina", "Grecia", "Italia", "Japón", "España"),
  sym = c("AR", "GR", "IT", "JP", "ES")
)

Filtro por países e incorporo las banderas.

Ocultar código
link <- "<img src='https://raw.githubusercontent.com/fonttools/region-flags/refs/heads/gh-pages/png/"

d <- cuisines |>
  mutate(country = tolower(country)) |>
  filter(str_detect(country, "arg|spa|ital|greek|japan")) |>
  select(name, country, calories, fat, carbs, protein, avg_rating) |>
  pivot_longer(
    cols = fat:protein,
    values_to = "valor",
    names_to = "nut"
  ) |>
  drop_na() |>
  full_join(nut_tbl, by = join_by(nut)) |>
  full_join(country_tbl, by = join_by(country)) |>
  mutate(flag = paste0(link, sym, ".png' width=50></img>")) |>
  mutate(flag = fct_reorder(flag, valor))

Figura

Etiquetas de los países y título.

Ocultar código
pais_label <- str_flatten_comma(
  paste0("<b style='color:", c6, ";'>", sort(country_tbl$pais), "</b>"),
  last = " y "
)

mi_titulo <- glue(
  "Contenido de nutrientes en la cocina de<br>{pais_label}"
)

Figura.

Ocultar código
g <- ggplot(
  d,
  aes(
    x = valor,
    y = tidytext::reorder_within(flag, valor, nut_trad, median),
    fill = pais
  )
) +
  geom_boxplot(
    color = c5,
    width = .7,
    linewidth = .4,
    outlier.color = c1,
    outlier.size = .2
  ) +
  facet_wrap(vars(nut_trad), scales = "free_y", ncol = 1, axes = "all_x") +
  nord::scale_fill_nord(palette = "mountain_forms") +
  tidytext::scale_y_reordered() +
  scale_x_continuous(
    breaks = scales::breaks_width(25),
    limits = c(0, 175),
    expand = c(0, 0)
  ) +
  coord_cartesian(clip = "off", expand = TRUE) +
  labs(x = NULL, y = NULL, title = mi_titulo, caption = mi_caption) +
  ggridges::theme_ridges(font_size = 15, font_family = "ubuntu") +
  theme(
    plot.background = element_rect(fill = c2),
    plot.margin = margin(r = 35, l = 35, b = 10, t = 10),
    plot.title = element_markdown(
      size = 32,
      color = c5,
      hjust = .5,
      margin = margin(b = 10)
    ),
    plot.title.position = "panel",
    plot.caption = element_markdown(
      size = 13,
      color = c6,
      lineheight = 1.3,
      margin = margin(t = 15)
    ),
    panel.background = element_rect(fill = c3),
    panel.spacing.y = unit(22, "pt"),
    panel.grid.major.y = element_blank(),
    panel.grid.major.x = element_line(color = c4),
    legend.position = "none",
    axis.text = element_text(color = c1, family = "jet", size = 12),
    axis.text.y = element_markdown(vjust = .5),
    axis.ticks = element_blank(),
    strip.background = element_blank(),
    strip.text = element_text(
      size = 20,
      hjust = 1,
      face = "italic",
      color = c5
    ),
    strip.clip = "off"
  )

Guardo.

Ocultar código
ggsave(
  plot = g,
  filename = "tidytuesday/2025/semana_37.png",
  width = 30,
  height = 30,
  units = "cm"
)
Subir
Semana 36
2024
Ejecutar el código
---
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_boxplot
execute:
  eval: false
  echo: true
  warning: false
title: "Semana 37"
date: last-modified
author: Víctor Gauto
---

Cantidad de nutrientes en platos de cinco países.

::: {.column-page-right}

![Semana 37, 2025](semana_37.png)

:::

## Paquetes

```{r}
library(glue)
library(ggtext)
library(showtext)
library(tidyverse)
```

## Estilos

Colores.

```{r}
c1 <- "#D8DEE9"
c2 <- "#2E3440"
c3 <- "#3B4252"
c4 <- "#434C5E"
c5 <- "white"
c6 <- "#74ACDF"
```

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 37, ",
  "<b>{{tastyR}}, allrecipes.com</b></span>"
)

autor <- glue("<span style='color:{c1};'>**Víctor Gauto**</span>")
icon_twitter <- glue("<span style='font-family:jet;'>&#xf099;</span>")
icon_instagram <- glue("<span style='font-family:jet;'>&#xf16d;</span>")
icon_github <- glue("<span style='font-family:jet;'>&#xf09b;</span>")
icon_mastodon <- glue("<span style='font-family:jet;'>&#xf0ad1;</span>")
icon_bsky <- glue("<span style='font-family:jet;'>&#xe28e;</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, 37)
cuisines <- tuesdata$cuisines
```

## Procesamiento

Me interesa la distribución de la cantidad de nutrientes (lípidos, carbohidratos y proteínas) en cinco países (Argentina, Grecia, Italia, Japón y España).

Creo etiquetas para nutrientes y países.

```{r}
nut_tbl <- tibble(
  nut = c("fat", "carbs", "protein"),
  nut_trad = c(
    "Lípidos (g/porción)",
    "Carbohidratos (g/porción)",
    "Proteínas (g/porción)"
  )
)

country_tbl <- tibble(
  country = c("argentinian", "greek", "italian", "japanese", "spanish"),
  pais = c("Argentina", "Grecia", "Italia", "Japón", "España"),
  sym = c("AR", "GR", "IT", "JP", "ES")
)
```

Filtro por países e incorporo las [banderas](https://github.com/fonttools/region-flags).

```{r}
link <- "<img src='https://raw.githubusercontent.com/fonttools/region-flags/refs/heads/gh-pages/png/"

d <- cuisines |>
  mutate(country = tolower(country)) |>
  filter(str_detect(country, "arg|spa|ital|greek|japan")) |>
  select(name, country, calories, fat, carbs, protein, avg_rating) |>
  pivot_longer(
    cols = fat:protein,
    values_to = "valor",
    names_to = "nut"
  ) |>
  drop_na() |>
  full_join(nut_tbl, by = join_by(nut)) |>
  full_join(country_tbl, by = join_by(country)) |>
  mutate(flag = paste0(link, sym, ".png' width=50></img>")) |>
  mutate(flag = fct_reorder(flag, valor))
```

## Figura

Etiquetas de los países y título.

```{r}
pais_label <- str_flatten_comma(
  paste0("<b style='color:", c6, ";'>", sort(country_tbl$pais), "</b>"),
  last = " y "
)

mi_titulo <- glue(
  "Contenido de nutrientes en la cocina de<br>{pais_label}"
)
```

Figura.

```{r}
g <- ggplot(
  d,
  aes(
    x = valor,
    y = tidytext::reorder_within(flag, valor, nut_trad, median),
    fill = pais
  )
) +
  geom_boxplot(
    color = c5,
    width = .7,
    linewidth = .4,
    outlier.color = c1,
    outlier.size = .2
  ) +
  facet_wrap(vars(nut_trad), scales = "free_y", ncol = 1, axes = "all_x") +
  nord::scale_fill_nord(palette = "mountain_forms") +
  tidytext::scale_y_reordered() +
  scale_x_continuous(
    breaks = scales::breaks_width(25),
    limits = c(0, 175),
    expand = c(0, 0)
  ) +
  coord_cartesian(clip = "off", expand = TRUE) +
  labs(x = NULL, y = NULL, title = mi_titulo, caption = mi_caption) +
  ggridges::theme_ridges(font_size = 15, font_family = "ubuntu") +
  theme(
    plot.background = element_rect(fill = c2),
    plot.margin = margin(r = 35, l = 35, b = 10, t = 10),
    plot.title = element_markdown(
      size = 32,
      color = c5,
      hjust = .5,
      margin = margin(b = 10)
    ),
    plot.title.position = "panel",
    plot.caption = element_markdown(
      size = 13,
      color = c6,
      lineheight = 1.3,
      margin = margin(t = 15)
    ),
    panel.background = element_rect(fill = c3),
    panel.spacing.y = unit(22, "pt"),
    panel.grid.major.y = element_blank(),
    panel.grid.major.x = element_line(color = c4),
    legend.position = "none",
    axis.text = element_text(color = c1, family = "jet", size = 12),
    axis.text.y = element_markdown(vjust = .5),
    axis.ticks = element_blank(),
    strip.background = element_blank(),
    strip.text = element_text(
      size = 20,
      hjust = 1,
      face = "italic",
      color = c5
    ),
    strip.clip = "off"
  )
```

Guardo.

```{r}
ggsave(
  plot = g,
  filename = "tidytuesday/2025/semana_37.png",
  width = 30,
  height = 30,
  units = "cm"
)
```

Creado con y

Víctor Gauto

  • Editar esta página
  • Informar sobre problema