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

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
    • Semana 38
    • Semana 39
    • Semana 40
    • Semana 41
    • Semana 42
  • 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 42

Semana 42

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

  • Ver el código fuente
GEOM_AAA
GEOM_BBB
GEOM_CCC
Autor

Víctor Gauto

Fecha de publicación

30 de octubre de 2025

Estaciones meteorológicas de Reino Unido y cantidad de horas de Sol.

Semana 42, 2025

Paquetes

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

Estilos

Colores.

Ocultar código
c1 <- "grey30"
c2 <- "grey90"
c3 <- "black"
c4 <- "#D6DF23"

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:{c4};'><span style='font-family:jet;'>",
  "{{<b>tidytuesdayR</b>}}</span> semana 42, ",
  "<b>UK Met Office</b>.</span>"
)

autor <- glue("<span style='color:{c4};'>**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:{c4};'>**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, 42)
historic_station_met <- tuesdata$historic_station_met
station_meta <- tuesdata$station_meta

Procesamiento

Me interesa indicar los sitios de las estaciones meteorológicas y la cantidad de horas solares.

Ocultar código
p <- terra::vect(station_meta, geom = c("lng", "lat"), crs = "EPSG:4326")

Obtengo las fronteras de Reino Unido y condados.

Ocultar código
uk1 <- rgeoboundaries::gb_adm1(country = "GBR") |>
  terra::vect()

uk2 <- rgeoboundaries::gb_adm2(country = "GBR") |>
  terra::vect()

Calculo la cantidad promedio de horas solares en cada estación meteorológica.

Ocultar código
v <- historic_station_met |>
  reframe(
    m = mean(sun, na.rm = TRUE),
    .by = station
  ) |>
  inner_join(terra::as.data.frame(p, geom = "xy"), by = join_by(station)) |>
  terra::vect(geom = c("x", "y"), crs = "EPSG:4326")

Figura

Título de la figura, título de la leyenda y logo.

Ocultar código
mi_titulo <- glue(
  "Estaciones Meteorológicas<br>de <b style='color: {c4};'>Reino Unido</b> ",
  "y cantidad<br>de horas solares mensuales"
)

mi_leyenda <- glue("Horas de<br><b style='color: {c4}'>Sol</b> al mes")

logo_tbl <- tibble(
  image = "https://upload.wikimedia.org/wikipedia/en/thumb/f/f4/Met_Office.svg/768px-Met_Office.svg.png",
  x = I(.9),
  y = I(.65)
)

Figura.

Ocultar código
g <- ggplot() +
  geom_spatvector(
    data = uk2,
    alpha = 1,
    fill = c2,
    color = c1,
    linewidth = .2,
    show.legend = FALSE
  ) +
  geom_spatvector(data = uk1, fill = NA, linewidth = .7, color = c1) +
  geom_spatvector(
    data = v,
    aes(fill = m),
    size = 15,
    shape = 21,
    color = c3
  ) +
  ggimage::geom_image(
    data = logo_tbl,
    aes(x, y, image = image),
    inherit.aes = FALSE,
    size = .1
  ) +
  annotate(
    geom = "richtext",
    x = I(-.02),
    y = I(.99),
    label = mi_titulo,
    family = "ubuntu",
    size = 12,
    color = c2,
    hjust = 0,
    vjust = 1,
    fill = NA,
    label.color = NA
  ) +
  scico::scale_fill_scico(palette = "buda", breaks = scales::breaks_width(10)) +
  coord_sf(expand = FALSE, clip = "off") +
  labs(
    fill = mi_leyenda,
    caption = mi_caption
  ) +
  theme_void(base_size = 26, base_family = "ubuntu") +
  theme(
    plot.background = element_rect(fill = c1),
    plot.margin = margin(t = 10, b = 10),
    plot.caption = element_markdown(
      color = c2,
      hjust = .5,
      lineheight = 1.3,
      margin = margin(t = 55)
    ),
    legend.position = "inside",
    legend.position.inside = c(0, 0),
    legend.justification.inside = c(0, 0),
    legend.title = element_markdown(
      margin = margin(b = 15, l = -30),
      color = c2,
      hjust = .5
    ),
    legend.text = element_text(
      family = "jet",
      size = rel(.7),
      margin = margin(l = 5),
      color = c2
    ),
    legend.key.width = unit(30, "pt"),
    legend.key.height = unit(70, "pt"),
    legend.box.spacing = unit(0, "pt"),
    legend.ticks = element_line(linewidth = 1, color = c1)
  )

Guardo.

Ocultar código
ggsave(
  plot = g,
  filename = "tidytuesday/2025/semana_42.png",
  width = 30,
  height = 53,
  units = "cm"
)
Subir
Semana 41
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_AAA
  - GEOM_BBB
  - GEOM_CCC
execute:
  eval: false
  echo: true
  warning: false
title: "Semana 42"
date: last-modified
author: Víctor Gauto
---

[Estaciones meteorológicas de Reino Unido](https://www.metoffice.gov.uk/) y cantidad de horas de Sol.


::: {.column-page-right}

![Semana 42, 2025](semana_42.png)

:::

## Paquetes

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

## Estilos

Colores.

```{r}
c1 <- "grey30"
c2 <- "grey90"
c3 <- "black"
c4 <- "#D6DF23"
```

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:{c4};'><span style='font-family:jet;'>",
  "{{<b>tidytuesdayR</b>}}</span> semana 42, ",
  "<b>UK Met Office</b>.</span>"
)

autor <- glue("<span style='color:{c4};'>**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:{c4};'>**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, 42)
historic_station_met <- tuesdata$historic_station_met
station_meta <- tuesdata$station_meta
```

## Procesamiento

Me interesa indicar los sitios de las estaciones meteorológicas y la cantidad de horas solares.

```{r}
p <- terra::vect(station_meta, geom = c("lng", "lat"), crs = "EPSG:4326")
```

Obtengo las fronteras de Reino Unido y condados.

```{r}
uk1 <- rgeoboundaries::gb_adm1(country = "GBR") |>
  terra::vect()

uk2 <- rgeoboundaries::gb_adm2(country = "GBR") |>
  terra::vect()
```

Calculo la cantidad promedio de horas solares en cada estación meteorológica.

```{r}
v <- historic_station_met |>
  reframe(
    m = mean(sun, na.rm = TRUE),
    .by = station
  ) |>
  inner_join(terra::as.data.frame(p, geom = "xy"), by = join_by(station)) |>
  terra::vect(geom = c("x", "y"), crs = "EPSG:4326")
```

## Figura

Título de la figura, título de la leyenda y logo.

```{r}
mi_titulo <- glue(
  "Estaciones Meteorológicas<br>de <b style='color: {c4};'>Reino Unido</b> ",
  "y cantidad<br>de horas solares mensuales"
)

mi_leyenda <- glue("Horas de<br><b style='color: {c4}'>Sol</b> al mes")

logo_tbl <- tibble(
  image = "https://upload.wikimedia.org/wikipedia/en/thumb/f/f4/Met_Office.svg/768px-Met_Office.svg.png",
  x = I(.9),
  y = I(.65)
)
```

Figura.

```{r}
g <- ggplot() +
  geom_spatvector(
    data = uk2,
    alpha = 1,
    fill = c2,
    color = c1,
    linewidth = .2,
    show.legend = FALSE
  ) +
  geom_spatvector(data = uk1, fill = NA, linewidth = .7, color = c1) +
  geom_spatvector(
    data = v,
    aes(fill = m),
    size = 15,
    shape = 21,
    color = c3
  ) +
  ggimage::geom_image(
    data = logo_tbl,
    aes(x, y, image = image),
    inherit.aes = FALSE,
    size = .1
  ) +
  annotate(
    geom = "richtext",
    x = I(-.02),
    y = I(.99),
    label = mi_titulo,
    family = "ubuntu",
    size = 12,
    color = c2,
    hjust = 0,
    vjust = 1,
    fill = NA,
    label.color = NA
  ) +
  scico::scale_fill_scico(palette = "buda", breaks = scales::breaks_width(10)) +
  coord_sf(expand = FALSE, clip = "off") +
  labs(
    fill = mi_leyenda,
    caption = mi_caption
  ) +
  theme_void(base_size = 26, base_family = "ubuntu") +
  theme(
    plot.background = element_rect(fill = c1),
    plot.margin = margin(t = 10, b = 10),
    plot.caption = element_markdown(
      color = c2,
      hjust = .5,
      lineheight = 1.3,
      margin = margin(t = 55)
    ),
    legend.position = "inside",
    legend.position.inside = c(0, 0),
    legend.justification.inside = c(0, 0),
    legend.title = element_markdown(
      margin = margin(b = 15, l = -30),
      color = c2,
      hjust = .5
    ),
    legend.text = element_text(
      family = "jet",
      size = rel(.7),
      margin = margin(l = 5),
      color = c2
    ),
    legend.key.width = unit(30, "pt"),
    legend.key.height = unit(70, "pt"),
    legend.box.spacing = unit(0, "pt"),
    legend.ticks = element_line(linewidth = 1, color = c1)
  )
```

Guardo.

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

Creado con y

Víctor Gauto

  • Editar esta página
  • Informar sobre problema