-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.R
More file actions
125 lines (105 loc) · 3.34 KB
/
script.R
File metadata and controls
125 lines (105 loc) · 3.34 KB
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
# paquetes ----------------------------------------------------------------
library(sf)
library(glue)
library(ggtext)
library(showtext)
library(tidyverse)
# fuentes -----------------------------------------------------------------
# paleta de colores
col <- MoMAColors::moma.colors(palette_name = "Smith")
c1 <- "#FFFFFF"
c2 <- "#000000"
# fuente: Ubuntu
font_add(
family = "ubuntu",
regular = "fuentes/Ubuntu-Regular.ttf",
bold = "fuentes/Ubuntu-Bold.ttf",
italic = "fuentes/Ubuntu-Italic.ttf")
# monoespacio & íconos
font_add(
family = "jet",
regular = "fuentes/JetBrainsMonoNLNerdFontMono-Regular.ttf")
showtext_auto()
showtext_opts(dpi = 300)
# caption
fuente <- glue(
"<b>Datos:</b> <span style='color:{col[4]};'>IGN</span>")
autor <- glue("<span style='color:{col[4]};'>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:{col[4]};'>vhgauto</span>")
sep <- glue("**|**")
mi_caption <- glue(
"{fuente} {sep} {autor} {sep} <b>{icon_github} {icon_twitter} ",
"{icon_instagram} {icon_mastodon}</b> {usuario}")
# datos -------------------------------------------------------------------
# departamentos
deptos <- st_read("extras/dptos_continental.gpkg") |>
st_transform(crs = 5346) |>
st_geometry()
col_pcias <- colorRampPalette(
c(col[5], scales::muted(col[5])), alpha = .6)(24)
# provincias
pcias <- st_read("extras/pcias_continental.gpkg") |>
mutate(fill_pcias = col_pcias)
# plantas potabilizadoras, explicando el estado actual
v <- st_read(
"planta_potabilizadora/puntos_de_fabricacion_y_procesamiento_BH220.json") |>
filter(fun == 6) |>
st_transform(crs = 5346)
# figura ------------------------------------------------------------------
# posición del subtítulo
x_sub <- st_bbox(deptos)$xmax
y_sub <- st_bbox(deptos)$ymax
mi_subtitle <- glue(
"En <b style='color: {c1}'>Argentina</b> hay en",
"funcionamiento <b style='color:#EF7923'>{nrow(v)}</b>",
"plantas de tratamiento",
"de agua.",
.sep = "<br>"
)
# figura
g <- ggplot() +
# provincias
geom_sf(
data = pcias, aes(fill = fill_pcias), linewidth = .4, color = c1,
show.legend = TRUE
) +
# departamentos
geom_sf(
data = deptos, fill = NA, color = c1, linewidth = .1, linetype = "55"
) +
# plantas potabilizadoras
geom_sf(
data = v, shape = 21, fill = col[4], size = 7, color = c2, alpha = .9
) +
# subtítulo
annotate(
geom = "richtext", x = x_sub*.84, y = y_sub*.66, label = mi_subtitle,
fill = NA, label.color = NA, size = 12, color = col[4], hjust = 0,
family = "ubuntu"
) +
scale_fill_identity() +
scale_shape_identity() +
labs(caption = mi_caption) +
theme_void() +
theme(
plot.margin = margin(r = 8, l = 8, t = 2),
plot.background = element_rect(
fill = col[5], color = col[2], linewidth = 3),
plot.caption = element_markdown(
family = "jet", color = c1, hjust = .5, size = 20,
margin = margin(b = 10))
)
# guardo
ggsave(
plot = g,
filename = "planta_potabilizadora/viz.png",
width = 30,
height = 65,
units = "cm"
)
# abro
browseURL(glue("{getwd()}/planta_potabilizadora/viz.png"))