-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.R
130 lines (108 loc) · 3.95 KB
/
script.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# paquetes ----------------------------------------------------------------
library(glue)
library(ggtext)
library(showtext)
library(ggpath)
library(tidyverse)
# fuente ------------------------------------------------------------------
# colores
c1 <- "#EAF3FF"
c2 <- "#123E7E"
c3 <- "#5773C0"
# fuente: Ubuntu
font_add(
family = "ubuntu",
regular = "fuente/Ubuntu-Regular.ttf",
bold = "fuente/Ubuntu-Bold.ttf",
italic = "fuente/Ubuntu-Italic.ttf")
# fuente: Victor
font_add(
family = "victor",
regular = "fuente/VictorMono-ExtraLight.ttf",
bold = "fuente/VictorMono-VariableFont_wght.ttf",
italic = "fuente/VictorMono-ExtraLightItalic.ttf")
# íconos
font_add("fa-brands", "icon/Font Awesome 6 Brands-Regular-400.otf")
showtext_auto()
showtext_opts(dpi = 300)
# caption
fuente <- glue(
"Datos: <span style='color:{c3};'><span style='font-family:mono;'>",
"{{<b>tidytuesdayR</b>}}</span> semana {5}. ",
"Groundhog Day Predictions, groundhog-day.com.</span>")
autor <- glue("<span style='color:{c3};'>**Víctor Gauto**</span>")
icon_twitter <- glue("<span style='font-family:fa-brands;'></span>")
icon_github <- glue("<span style='font-family:fa-brands;'></span>")
icon_mastodon <- glue("<span style='font-family:fa-brands;'></span>")
usuario <- glue("<span style='color:{c3};'>**vhgauto**</span>")
sep <- glue("**|**")
mi_caption <- glue(
"{fuente}<br>{autor} {sep} {icon_github} {icon_twitter} {icon_mastodon}
{usuario}")
# datos -------------------------------------------------------------------
tuesdata <- tidytuesdayR::tt_load(2024, 5)
groundhogs <- tuesdata$groundhogs
# me interesan las imágenes de las marmotas únicamente
d <- groundhogs |>
filter(is_groundhog) |>
select(image, name) |>
arrange(name) |>
mutate(name = str_remove(name, " the Groundhog")) |>
mutate(nro = row_number()) |>
mutate(label = glue(
"<b style='font-family:victor; font-size:8pt; color: {c3}'>{nro}.</b>",
"{name}")) |>
mutate(label = fct_inorder(label))
# figura ------------------------------------------------------------------
# etiquetas de los paneles (facet_wrap)
nombres <- as.character(d$label)
names(nombres) <- d$nro
# título y subtítulo
mi_title <- "Marmotas pronosticadoras"
mi_subtitle <- glue(
"El **Día de la Marmota** consiste en dos creencias populares,",
"una sobre el **clima** (soleado o nublado) y otra sobre **animales que",
"hibernan** (si ya están despiertos o no). La tradición moderna en esencia",
"tiene sus raíces en el clima: si es un día soleado, la **marmota** ve su",
"sombra, lo que significa un *invierno* más largo. Si está nublado, se",
"adelanta la *primavera*.",
.sep = " ") |>
str_wrap(width = 65) |>
str_replace_all(fixed("\n"), "<br>")
mi_subtitle_tbl <- tibble(
nro = 33) |>
mutate(subtitulo = mi_subtitle)
# figura
g <- ggplot(d, aes(0, 0, path = image)) +
geom_from_path(width = 1) +
geom_richtext(
data = mi_subtitle_tbl, aes(0, 0, label = subtitulo), hjust = 0, color = c2,
family= "ubuntu", size = 4.5, inherit.aes = FALSE, fill = NA,
label.color = NA) +
facet_wrap(vars(nro), ncol = 5, labeller = as_labeller(nombres)) +
coord_cartesian(expand = FALSE, clip = "off") +
labs(title = mi_title, caption = mi_caption) +
theme_void() +
theme(
aspect.ratio = 1,
plot.background = element_rect(fill = c1, color = c3, linewidth = 3),
plot.margin = margin(r = 20, l = 20, t = 10, b = 10),
plot.title = element_text(
family = "miltonian", size = 61, color = c2, hjust = .5,
margin = margin(b = 15)),
plot.caption = element_markdown(family = "ubuntu", color = c3, size = 13),
panel.spacing.x = unit(1, "line"),
panel.spacing.y = unit(1.1, "line"),
strip.text = element_markdown(
color = c2, family = "ubuntu", size = 12, face = "bold",
hjust = 0)
)
# guardo
ggsave(
plot = g,
filename = "2024/s05/viz.png",
width = 30,
height = 47.51,
units = "cm")
# abro
browseURL("2024/s05/viz.png")