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

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
  • 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 de un problema
  1. 2025
  2. Semana 26

Semana 26

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

  • Ver el código fuente
geom_line
geom_richtext
Autor

Víctor Gauto

Fecha de publicación

8 de julio de 2025

Relación entre la gasolina regular respecto de la premium.

Semana 26, 2025

Paquetes

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

Estilos

Colores.

Ocultar código
c1 <- "gold"
c2 <- "grey50"
c3 <- "grey40"
c4 <- "grey20"
c5 <- "grey10"
c6 <- "white"

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"
)

font_add(
  family = "bebas neue",
  regular = "././fuente/BebasNeue-Regular.ttf"
)

showtext_auto()
showtext_opts(dpi = 300)

Epígrafe

Ocultar código
fuente <- glue(
    "Datos: <span style='color:{c2};'><span style='font-family:jet;'>",
    "{{<b>tidytuesdayR</b>}}</span> semana 26, ",
    "<b>U.S. Energy Information Administration</b>.</span>"
)

autor <- glue("<span style='color:{c2};'>**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:{c2};'>**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, 26)
gas_prices <- tuesdata$weekly_gas_prices

Procesamiento

Me interesa la evolución de la relación entre el precio de la gasolina común respecto de la premium.

Ocultar código
d <- gas_prices |> 
  filter(
    fuel == "gasoline",
    grade %in% c("regular", "premium"),
    formulation == "all"
  ) |> 
  select(-fuel, -formulation) |> 
  pivot_wider(
    names_from = grade,
    values_from = price,
    id_cols = date
  ) |> 
  drop_na() |> 
  mutate(r = (premium-regular)/regular)

Figura

El paquete {ggfx} sirve para generar el brillo de la caja de texto y la línea de evolución.

Creo dos títulos: mi_titulo1 para generar el espacio y darle brillo al contorno, y mi_titulo2 para mostrar el texto, quitando el contorno.

Ocultar código
mi_titulo1 <- glue(
  "Costo extra de la gasolina<br><b style='color: white'>premium</b> respecto 
  de la<br><b style='color: white'>común</b> en **EE.UU.**"
)

mi_titulo2 <- glue(
  "Costo extra de la gasolina<br>premium respecto 
  de la<br>común en **EE.UU.**"
)

Figura.

Ocultar código
g <- ggplot(d, aes(date, r)) +
  ggfx::with_blur(
    geom_line(color = c1, lineend = "round", linewidth = 1, alpha = .6),
    sigma = 6,
    stack = TRUE
  ) +
  geom_line(color = c1, lineend = "round", linewidth = .2, alpha = 1) +
  ggfx::with_blur(
    geom_richtext(
      x = I(.02), y = I(.98), label = mi_titulo2, hjust = 0, vjust = 1,
      color = NA, family = "ubuntu", size = 9, label.r = unit(0, "mm"),
      label.padding = unit(4, "mm"), fill = c5, label.color = c6,
      label.size = unit(.6, "mm")
    ),
    sigma = 10,
    stack = TRUE
  ) +
  annotate(
    geom = "richtext",
    x = I(.02),
    y = I(.98),
    label = mi_titulo1,
    hjust = 0,
    vjust = 1,
    family = "ubuntu",
    fill = NA,
    color = c3,
    label.color = NA,
    label.r = unit(0, "mm"),
    label.padding = unit(4, "mm"),
    size = 9
  ) +
  scale_x_date(
    date_labels = "'%y",
    breaks = seq.Date(ymd(19900101), ymd(20270101), "5 year"),
    minor_breaks = "1 year",
    limits = c(ymd(19940101), ymd(20260101)),
    expand = c(0, 0)
  ) +
  scale_y_continuous(
    labels = scales::label_percent(), 
    breaks = scales::breaks_width(.1),
    minor_breaks = scales::breaks_width(.02),
    limits = c(.05, .4),
    expand = c(0, 0)
  ) +
  coord_cartesian(clip = "off") +
  labs(x = NULL, y = NULL, caption = mi_caption) +
  theme_void(base_size = 20, base_family = "bebas neue") +
  theme(
    aspect.ratio = 1,
    plot.margin = margin(20, 20, 20, 20),
    plot.background = element_rect(fill = c5, color = NA),
    plot.caption = element_markdown(
      family = "ubuntu", color = c3, size = rel(.7), lineheight = 1.3,
      margin = margin(b = 5, t = 20)
    ),
    panel.background = element_blank(),
    panel.grid.major = element_line(
      linetype = "55", linewidth = .2, color = c3
    ),
    panel.grid.minor = element_line(
      linetype = "55", linewidth = .2, color = c4
    ),
    axis.text = element_text(size = rel(1.4), color = c2),
    axis.text.x = element_text(margin = margin(t = 5)),
    axis.text.y = element_text(margin = margin(r = 5))
  )

Guardo.

Ocultar código
ggsave(
  plot = g,
  filename = "tidytuesday/2025/semana_26.png",
  width = 30,
  height = 31,
  units = "cm"
)
Subir
Semana 25
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_line
  - geom_richtext
execute:
  eval: false
  echo: true
  warning: false
title: "Semana 26"
date: last-modified
author: Víctor Gauto
---

Relación entre la gasolina regular respecto de la premium.

![Semana 26, 2025](semana_26.png)

## Paquetes

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

## Estilos

Colores.

```{r}
c1 <- "gold"
c2 <- "grey50"
c3 <- "grey40"
c4 <- "grey20"
c5 <- "grey10"
c6 <- "white"
```

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"
)

font_add(
  family = "bebas neue",
  regular = "././fuente/BebasNeue-Regular.ttf"
)

showtext_auto()
showtext_opts(dpi = 300)
```

## Epígrafe

```{r}
fuente <- glue(
    "Datos: <span style='color:{c2};'><span style='font-family:jet;'>",
    "{{<b>tidytuesdayR</b>}}</span> semana 26, ",
    "<b>U.S. Energy Information Administration</b>.</span>"
)

autor <- glue("<span style='color:{c2};'>**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:{c2};'>**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, 26)
gas_prices <- tuesdata$weekly_gas_prices
```

## Procesamiento

Me interesa la evolución de la relación entre el precio de la gasolina común respecto de la premium.

```{r}
d <- gas_prices |> 
  filter(
    fuel == "gasoline",
    grade %in% c("regular", "premium"),
    formulation == "all"
  ) |> 
  select(-fuel, -formulation) |> 
  pivot_wider(
    names_from = grade,
    values_from = price,
    id_cols = date
  ) |> 
  drop_na() |> 
  mutate(r = (premium-regular)/regular)
```

## Figura

El paquete [`{ggfx}`](https://ggfx.data-imaginist.com/index.html) sirve para generar el brillo de la caja de texto y la línea de evolución.

Creo dos títulos: `mi_titulo1` para generar el espacio y darle brillo al contorno, y `mi_titulo2` para mostrar el texto, quitando el contorno.

```{r}
mi_titulo1 <- glue(
  "Costo extra de la gasolina<br><b style='color: white'>premium</b> respecto 
  de la<br><b style='color: white'>común</b> en **EE.UU.**"
)

mi_titulo2 <- glue(
  "Costo extra de la gasolina<br>premium respecto 
  de la<br>común en **EE.UU.**"
)
```

Figura.

```{r}
g <- ggplot(d, aes(date, r)) +
  ggfx::with_blur(
    geom_line(color = c1, lineend = "round", linewidth = 1, alpha = .6),
    sigma = 6,
    stack = TRUE
  ) +
  geom_line(color = c1, lineend = "round", linewidth = .2, alpha = 1) +
  ggfx::with_blur(
    geom_richtext(
      x = I(.02), y = I(.98), label = mi_titulo2, hjust = 0, vjust = 1,
      color = NA, family = "ubuntu", size = 9, label.r = unit(0, "mm"),
      label.padding = unit(4, "mm"), fill = c5, label.color = c6,
      label.size = unit(.6, "mm")
    ),
    sigma = 10,
    stack = TRUE
  ) +
  annotate(
    geom = "richtext",
    x = I(.02),
    y = I(.98),
    label = mi_titulo1,
    hjust = 0,
    vjust = 1,
    family = "ubuntu",
    fill = NA,
    color = c3,
    label.color = NA,
    label.r = unit(0, "mm"),
    label.padding = unit(4, "mm"),
    size = 9
  ) +
  scale_x_date(
    date_labels = "'%y",
    breaks = seq.Date(ymd(19900101), ymd(20270101), "5 year"),
    minor_breaks = "1 year",
    limits = c(ymd(19940101), ymd(20260101)),
    expand = c(0, 0)
  ) +
  scale_y_continuous(
    labels = scales::label_percent(), 
    breaks = scales::breaks_width(.1),
    minor_breaks = scales::breaks_width(.02),
    limits = c(.05, .4),
    expand = c(0, 0)
  ) +
  coord_cartesian(clip = "off") +
  labs(x = NULL, y = NULL, caption = mi_caption) +
  theme_void(base_size = 20, base_family = "bebas neue") +
  theme(
    aspect.ratio = 1,
    plot.margin = margin(20, 20, 20, 20),
    plot.background = element_rect(fill = c5, color = NA),
    plot.caption = element_markdown(
      family = "ubuntu", color = c3, size = rel(.7), lineheight = 1.3,
      margin = margin(b = 5, t = 20)
    ),
    panel.background = element_blank(),
    panel.grid.major = element_line(
      linetype = "55", linewidth = .2, color = c3
    ),
    panel.grid.minor = element_line(
      linetype = "55", linewidth = .2, color = c4
    ),
    axis.text = element_text(size = rel(1.4), color = c2),
    axis.text.x = element_text(margin = margin(t = 5)),
    axis.text.y = element_text(margin = margin(r = 5))
  )
```

Guardo.

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

Creado con y

Víctor Gauto

  • Editar esta página
  • Informar de un problema