-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.R
139 lines (114 loc) · 4.08 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
131
132
133
134
135
136
137
138
139
# paquetes ----------------------------------------------------------------
library(glue)
library(ggtext)
library(showtext)
library(tidyverse)
# fuente ------------------------------------------------------------------
# colores
c1 <- "grey90"
c2 <- "#A82203"
c3 <- "#003967"
c4 <- "#ABA366"
# 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(
family = "jet",
regular = "fuente/JetBrainsMonoNLNerdFontMono-Regular.ttf")
showtext_auto()
showtext_opts(dpi = 300)
# caption
fuente <- glue(
"Datos: <span style='color:{c3};'><span style='font-family:mono;'>",
"{{<b>tidytuesdayR</b>}}</span> semana {16}. ",
"ShinyConf2024.</span>")
autor <- glue("<span style='color:{c3};'>**Víctor Gauto**</span>")
icon_twitter <- glue("<span style='font-family:jet;'></span>")
icon_instagram <- glue("<span style='font-family:jet;'></span>")
icon_github <- glue("<span style='font-family:jet;'></span>")
icon_mastodon <- glue("<span style='font-family:jet;'>󰫑</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} {usuario}")
# datos -------------------------------------------------------------------
tuesdata <- tidytuesdayR::tt_load(2024, 16)
# me interesan los paquetes que dependen de {ggplot2}
package_details <- tuesdata$package_details
# selecciono los paquetes
p <- package_details |>
filter(str_detect(Depends, "ggplot2")) |>
select(Package)
# cantidad de paquetes
nrow(p) # 400
# cantidad de filas y columnas
eje_x <- 10
eje_y <- 400/eje_x
# paleta de colores
paleta <- MetBrewer::met.brewer(name = "Juarez", n = eje_x)
# agrego colores y formo las filas con los nombres de los paquetes
d <- p |>
mutate(x = rep(1:eje_x, length.out = nrow(p))) |>
mutate(y = rep(1:eje_y, each = 400/eje_y, length.out = nrow(p))) |>
mutate(color = rep(paleta, length.out = nrow(p))) |>
mutate(label = glue("<b style='color:{color}'>{Package}</b>")) |>
reframe(
l = str_flatten(label, " "),
.by = y
)
# figura ------------------------------------------------------------------
# logos de {shiny} y {ggplot2}
logo_shiny <- "https://raw.githubusercontent.com/rstudio/shiny/main/man/figures/logo.png"
logo_ggplot2 <- "https://raw.githubusercontent.com/tidyverse/ggplot2/main/man/figures/logo.png"
# título y subtítulo
mi_title <- glue(
"<img src='{logo_ggplot2}' height=100></img>.........................",
"<img src='{logo_shiny}' height=100></img>")
mi_subtitle <- glue(
"Lista de paquetes que dependen de<br>",
"<span style='font-family:jet'>{{ggplot2}</span>, asociados a ",
"<span style='font-family:jet'>{{shiny}}</span>"
)
# figura
g <- ggplot(d, aes(0, y/1.3, label = l)) +
geom_richtext(
family = "jet", size = 3.5, hjust = .5, fill = NA, label.color = NA,
fontface = "bold") +
coord_cartesian(
xlim = c(-2, 2), ylim = c(0, 29), expand = TRUE, clip = "off") +
labs(title = mi_title, subtitle = mi_subtitle, caption = mi_caption) +
theme_void() +
theme(
aspect.ratio = 1,
plot.margin = margin(l = 50, r = 50, t = 2.4),
plot.background = element_rect(fill = c1, color = c4, linewidth = 3),
plot.title = element_markdown(
hjust = .5, size = 50, color = c1, margin = margin(t = 10)),
plot.subtitle = element_markdown(
family = "ubuntu", color = c3, size = 14, hjust = .5,
margin = margin(t = -75), lineheight = unit(1.2, "line")),
plot.caption = element_markdown(
color = c2, family = "ubuntu", size = 10, lineheight = unit(1.2, "line"),
margin = margin(r = -10, b = 10))
)
# guardo
ggsave(
plot = g,
filename = "2024/s16/viz.png",
width = 30,
height = 33.5,
units = "cm"
)
# abro
browseURL("2024/s16/viz.png")