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

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
  • 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 35

Semana 35

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

  • Ver el código fuente
geom_col
geom_spatvector
Autor

Víctor Gauto

Fecha de publicación

11 de septiembre de 2025

Ubicaciones de ranas en Australia.

Semana 35, 2025

Paquetes

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

Estilos

Colores.

Ocultar código
c1 <- "#AD8CAE"
c2 <- "#BF616A"
c3 <- "grey95"
c4 <- "#485D32"

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 35, ",
  "<b>FrogID</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, 35)
frogID_data <- tuesdata$frogID_data

Procesamiento

Me interesa ver un mapa de las posiciones de las ranas registradas y la cantidad de registros por división de Australia.

Creo vector de puntos.

Ocultar código
v <- frogID_data |>
  terra::vect(
    geom = c("decimalLongitude", "decimalLatitude"),
    crs = "EPSG:4326"
  )

Obtengo vector de Australia y recorto la extensión.

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

aus_ext <- terra::ext(aus)
aus_ext2 <- terra::ext(112, 156, aus_ext$ymin, aus_ext$ymax) |>
  terra::vect(crs = "EPSG:4326")

aus2 <- terra::crop(aus, aus_ext2)

v2 <- sf::st_intersection(sf::st_as_sf(v), sf::st_as_sf(aus2))

Cuento la cantidad por estado.

Ocultar código
d <- count(v2, shapeName) |>
  sf::st_drop_geometry() |>
  mutate(shapeName = fct_reorder(shapeName, n))

Figura

Título y subtítulo.

Ocultar código
mi_titulo <- glue(
  "Registros de <b style='color: {c4}'>ranas</b> en Australia"
)

mi_subitulo <- glue(
  "Se muestran **{nrow(frogID_data)}** ocurrencias, que incluyen {length(unique(frogID_data$scientificName))} especies de ranas."
)

Figura de columnas.

Ocultar código
g_col <- ggplot(d, aes(n, shapeName, fill = shapeName)) +
  geom_col(show.legend = FALSE) +
  scale_fill_manual(
    values = alpha(
      c(nord::nord(palette = "aurora"), nord::nord(palette = "lumina")),
      1
    )
  ) +
  scale_x_continuous(
    labels = scales::label_number(
      big.mark = ".",
      decimal.mark = ",",
      scale = 1e-3
    ),
    breaks = scales::breaks_width(1e4)
  ) +
  coord_cartesian(clip = "off") +
  labs(x = "Cantidad de registros (en miles)", y = NULL) +
  theme_void() +
  theme(
    plot.background = element_rect(fill = "grey95", color = NA),
    panel.grid.major.x = element_line(color = "grey90", linetype = 2),
    legend.position = "none",
    axis.text.x = element_text(family = "jet"),
    axis.text.y = element_text(hjust = 1),
    axis.title.x = element_text(hjust = 1.2, margin = margin(t = 5))
  )

Mapa de Australia con los puntos.

Ocultar código
g <- ggplot() +
  geom_spatvector(
    data = aus2,
    aes(fill = shapeName),
    linewidth = .1
  ) +
  geom_spatvector(
    data = v2,
    alpha = 1 / 20,
    size = 2,
    color = "white",
    fill = "black",
    stroke = .2,
    shape = 21
  ) +
  scale_fill_manual(
    values = alpha(
      c(nord::nord(palette = "aurora"), nord::nord(palette = "lumina")),
      1
    )
  ) +
  theme_void(base_size = 5, base_family = "ubuntu") +
  theme(
    legend.position = "none"
  )

Figura compuesta.

Ocultar código
g_comp <- g +
  inset_element(
    g_col,
    left = .01,
    bottom = .01,
    right = .45,
    top = .2
  ) +
  plot_annotation(
    title = mi_titulo,
    subtitle = mi_subitulo,
    caption = mi_caption,
    theme = theme(
      plot.background = element_rect(fill = NA, color = NA),
      plot.title = element_markdown(
        family = "ubuntu",
        size = 25,
        margin = margin(t = 15)
      ),
      plot.subtitle = element_markdown(
        family = "ubuntu",
        size = 17,
        margin = margin(t = 10)
      ),
      plot.caption = element_markdown(
        family = "ubuntu",
        color = c2,
        size = 11,
        lineheight = 1.3,
        margin = margin(b = 10, r = -4)
      )
    )
  )

Guardo.

Ocultar código
ggsave(
  plot = g_comp,
  filename = "tidytuesday/2025/semana_35.png",
  width = 30,
  height = 30,
  units = "cm"
)
Subir
Semana 34
Semana 36
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_col
  - geom_spatvector
execute:
  eval: false
  echo: true
  warning: false
title: "Semana 35"
date: last-modified
author: Víctor Gauto
---

Ubicaciones de ranas en Australia.

::: {.column-page-right}

![Semana 35, 2025](semana_35.png)

:::

## Paquetes

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

## Estilos

Colores.

```{r}
c1 <- "#AD8CAE"
c2 <- "#BF616A"
c3 <- "grey95"
c4 <- "#485D32"
```

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 35, ",
  "<b>FrogID</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, 35)
frogID_data <- tuesdata$frogID_data
```

## Procesamiento

Me interesa ver un mapa de las posiciones de las ranas registradas y la cantidad de registros por división de Australia.

Creo vector de puntos.

```{r}
v <- frogID_data |>
  terra::vect(
    geom = c("decimalLongitude", "decimalLatitude"),
    crs = "EPSG:4326"
  )
```

Obtengo vector de Australia y recorto la extensión.

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

aus_ext <- terra::ext(aus)
aus_ext2 <- terra::ext(112, 156, aus_ext$ymin, aus_ext$ymax) |>
  terra::vect(crs = "EPSG:4326")

aus2 <- terra::crop(aus, aus_ext2)

v2 <- sf::st_intersection(sf::st_as_sf(v), sf::st_as_sf(aus2))
```

Cuento la cantidad por estado.

```{r}
d <- count(v2, shapeName) |>
  sf::st_drop_geometry() |>
  mutate(shapeName = fct_reorder(shapeName, n))
```

## Figura

Título y subtítulo.

```{r}
mi_titulo <- glue(
  "Registros de <b style='color: {c4}'>ranas</b> en Australia"
)

mi_subitulo <- glue(
  "Se muestran **{nrow(frogID_data)}** ocurrencias, que incluyen {length(unique(frogID_data$scientificName))} especies de ranas."
)
```

Figura de columnas.

```{r}
g_col <- ggplot(d, aes(n, shapeName, fill = shapeName)) +
  geom_col(show.legend = FALSE) +
  scale_fill_manual(
    values = alpha(
      c(nord::nord(palette = "aurora"), nord::nord(palette = "lumina")),
      1
    )
  ) +
  scale_x_continuous(
    labels = scales::label_number(
      big.mark = ".",
      decimal.mark = ",",
      scale = 1e-3
    ),
    breaks = scales::breaks_width(1e4)
  ) +
  coord_cartesian(clip = "off") +
  labs(x = "Cantidad de registros (en miles)", y = NULL) +
  theme_void() +
  theme(
    plot.background = element_rect(fill = "grey95", color = NA),
    panel.grid.major.x = element_line(color = "grey90", linetype = 2),
    legend.position = "none",
    axis.text.x = element_text(family = "jet"),
    axis.text.y = element_text(hjust = 1),
    axis.title.x = element_text(hjust = 1.2, margin = margin(t = 5))
  )
```

Mapa de Australia con los puntos.

```{r}
g <- ggplot() +
  geom_spatvector(
    data = aus2,
    aes(fill = shapeName),
    linewidth = .1
  ) +
  geom_spatvector(
    data = v2,
    alpha = 1 / 20,
    size = 2,
    color = "white",
    fill = "black",
    stroke = .2,
    shape = 21
  ) +
  scale_fill_manual(
    values = alpha(
      c(nord::nord(palette = "aurora"), nord::nord(palette = "lumina")),
      1
    )
  ) +
  theme_void(base_size = 5, base_family = "ubuntu") +
  theme(
    legend.position = "none"
  )
```

Figura compuesta.

```{r}
g_comp <- g +
  inset_element(
    g_col,
    left = .01,
    bottom = .01,
    right = .45,
    top = .2
  ) +
  plot_annotation(
    title = mi_titulo,
    subtitle = mi_subitulo,
    caption = mi_caption,
    theme = theme(
      plot.background = element_rect(fill = NA, color = NA),
      plot.title = element_markdown(
        family = "ubuntu",
        size = 25,
        margin = margin(t = 15)
      ),
      plot.subtitle = element_markdown(
        family = "ubuntu",
        size = 17,
        margin = margin(t = 10)
      ),
      plot.caption = element_markdown(
        family = "ubuntu",
        color = c2,
        size = 11,
        lineheight = 1.3,
        margin = margin(b = 10, r = -4)
      )
    )
  )
```

Guardo.

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

Creado con y

Víctor Gauto

  • Editar esta página
  • Informar de un problema