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

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 30

Semana 30

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

  • Ver el código fuente
geom_histogram
geom_point_svg
Autor

Víctor Gauto

Fecha de publicación

23 de septiembre de 2025

Distribución de la duración de películas en Netflix.

Semana 30, 2025

Paquetes

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

Estilos

Colores.

Ocultar código
c1 <- "#D81F26"
c2 <- "black"
c3 <- "white"
c4 <- "grey30"

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:{c3};'><span style='font-family:jet;'>",
  "{{<b>tidytuesdayR</b>}}</span> semana 30, ",
  "<b><span style='color: {c1}'>NETFLIX</b> 
  Engagement Reports</b>.</span>"
)

autor <- glue("<span style='color:{c3};'>**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:{c3};'>**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, 30)
movies <- tuesdata$movies
shows <- tuesdata$shows

Procesamiento

Me interesa la duración de las películas. Conservo únicamente aquellas que duran menos de 4 horas para generar un histograma.

Ocultar código
d <- movies |> 
  mutate(dur = duration(runtime)) |> 
  select(title, dur) |> 
  distinct() |> 
  drop_na() |> 
  filter(dur < 3600*4)

Duración promedio de las películas.

Ocultar código
hora <- floor(mean(d$dur)/3600)
minuto <- floor((mean(d$dur) - hora*3600)/60)

Figura

Logo, título y subtítulo.

Ocultar código
logo_link <- "https://upload.wikimedia.org/wikipedia/commons/0/08/Netflix_2015_logo.svg"
logo_txt <- paste(readLines(logo_link), collapse = "\n")

mi_titulo <- glue(
  "Distribución de duraciones de 
  {format(nrow(d), big.mark = '.', decimal.mark = ',')} películas 
  en <b style='color: {c1}'>NETFLIX</b>."
)

mi_subtitulo <- glue(
  "La película promedio <br>dura <b style='color: {c3}'>{hora} 
  hora {minuto} minutos</b>."
)

Figura.

Ocultar código
g <- ggplot(d, aes(dur)) +
  geom_histogram(
    binwidth = 2*60, color = c2, fill = c1, linewidth = 1
  ) +
  ggsvg::geom_point_svg(
    x = I(.1), y = I(.3), svg = logo_txt, size = 40
  ) +
  scale_x_continuous(
    breaks = 1:3*3600,
    labels = paste0(1:3, "H")
  ) +
  annotate(
    geom = "richtext",
    x = I(.6),
    y = I(.8),
    label = mi_subtitulo,
    color = c4,
    family = "ubuntu",
    label.color = NA,
    size = 7,
    fill = NA,
    hjust = 0,
    vjust = 1
  ) +
  coord_cartesian(expand = FALSE, clip = "off") +
  labs(
    title = mi_titulo,
    caption = mi_caption
  ) +
  theme_void(base_family = "ubuntu", base_size = 16) +
  theme(
    aspect.ratio = 1,
    plot.margin = margin(t = 10, b = 10),
    plot.background = element_rect(fill = c2),
    plot.title.position = "plot",
    plot.title = element_textbox_simple(
      color = c3, size = rel(1.75), margin = margin(b = 15)
    ),
    plot.caption = element_markdown(
      color = c4, lineheight = 1.3, margin = margin(t = 10), 
      size = rel(.9)
    ),
    panel.background = element_blank(),
    panel.grid.major.y = element_line(
      color = c4, linewidth = .2, linetype = "FF"
    ),
    axis.text = element_text(
      color = c4, family = "jet", margin = margin(t = 10)
    ),
    axis.text.y = element_text(margin = margin(r = 5))
  )

Guardo.

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

Distribución de la duración de películas en **Netflix**.

![Semana 30, 2025](semana_30.png)

## Paquetes

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

## Estilos

Colores.

```{r}
c1 <- "#D81F26"
c2 <- "black"
c3 <- "white"
c4 <- "grey30"
```

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 30, ",
  "<b><span style='color: {c1}'>NETFLIX</b> 
  Engagement Reports</b>.</span>"
)

autor <- glue("<span style='color:{c3};'>**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:{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, 30)
movies <- tuesdata$movies
shows <- tuesdata$shows
```

## Procesamiento

Me interesa la duración de las películas. Conservo únicamente aquellas que duran menos de 4 horas para generar un histograma.

```{r}
d <- movies |> 
  mutate(dur = duration(runtime)) |> 
  select(title, dur) |> 
  distinct() |> 
  drop_na() |> 
  filter(dur < 3600*4)
```

Duración promedio de las películas.

```{r}
hora <- floor(mean(d$dur)/3600)
minuto <- floor((mean(d$dur) - hora*3600)/60)
```

## Figura

Logo, título y subtítulo.

```{r}
logo_link <- "https://upload.wikimedia.org/wikipedia/commons/0/08/Netflix_2015_logo.svg"
logo_txt <- paste(readLines(logo_link), collapse = "\n")

mi_titulo <- glue(
  "Distribución de duraciones de 
  {format(nrow(d), big.mark = '.', decimal.mark = ',')} películas 
  en <b style='color: {c1}'>NETFLIX</b>."
)

mi_subtitulo <- glue(
  "La película promedio <br>dura <b style='color: {c3}'>{hora} 
  hora {minuto} minutos</b>."
)
```

Figura.

```{r}
g <- ggplot(d, aes(dur)) +
  geom_histogram(
    binwidth = 2*60, color = c2, fill = c1, linewidth = 1
  ) +
  ggsvg::geom_point_svg(
    x = I(.1), y = I(.3), svg = logo_txt, size = 40
  ) +
  scale_x_continuous(
    breaks = 1:3*3600,
    labels = paste0(1:3, "H")
  ) +
  annotate(
    geom = "richtext",
    x = I(.6),
    y = I(.8),
    label = mi_subtitulo,
    color = c4,
    family = "ubuntu",
    label.color = NA,
    size = 7,
    fill = NA,
    hjust = 0,
    vjust = 1
  ) +
  coord_cartesian(expand = FALSE, clip = "off") +
  labs(
    title = mi_titulo,
    caption = mi_caption
  ) +
  theme_void(base_family = "ubuntu", base_size = 16) +
  theme(
    aspect.ratio = 1,
    plot.margin = margin(t = 10, b = 10),
    plot.background = element_rect(fill = c2),
    plot.title.position = "plot",
    plot.title = element_textbox_simple(
      color = c3, size = rel(1.75), margin = margin(b = 15)
    ),
    plot.caption = element_markdown(
      color = c4, lineheight = 1.3, margin = margin(t = 10), 
      size = rel(.9)
    ),
    panel.background = element_blank(),
    panel.grid.major.y = element_line(
      color = c4, linewidth = .2, linetype = "FF"
    ),
    axis.text = element_text(
      color = c4, family = "jet", margin = margin(t = 10)
    ),
    axis.text.y = element_text(margin = margin(r = 5))
  )
```

Guardo.

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

Creado con y

Víctor Gauto

  • Editar esta página
  • Informar sobre problema