-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript__001.R
119 lines (98 loc) · 3.48 KB
/
script__001.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
# paquetes ----------------------------------------------------------------
library(sf)
library(tidyverse)
library(glue)
library(showtext)
library(ggtext)
# fuentes -----------------------------------------------------------------
# RColorBrewer Blues
RColorBrewer::display.brewer.pal(n = 9, name = "Blues")
c1 <- "#08306B"
c2 <- "#08519C"
c3 <- "#C6DBEF"
c4 <- "#F7FBFF"
# texto
font_add_google(name = "Ubuntu", family = "ubuntu", db_cache = FALSE)
showtext_auto()
showtext_opts(dpi = 300)
# íconos
font_add("fa-brands", "icon/Font Awesome 6 Brands-Regular-400.otf")
# caption
fuente <- glue("Datos: <span style='color:{c3};'>Instituto Geográfico Nacional</span>")
epsg <- glue("EPSG: <span style='color:{c3};'>5346</span>")
autor <- glue("Autor: <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>")
usuario <- glue("<span style='color:{c3};'>**vhgauto**</span>")
sep <- glue("**|**")
mi_caption <- glue("{fuente} {sep} {epsg} {sep} {autor} {sep} {icon_github} {icon_twitter} {usuario}")
# datos -------------------------------------------------------------------
browseURL("https://www.ign.gob.ar/NuestrasActividades/InformacionGeoespacial/CapasSIG")
# leo los vectores de las redes viales
l_nacional <- st_read("ign_red_vial/LíneaRed vial nacional.json") |>
mutate(obj = "nacional") |>
select(obj, geometry)
l_provincial <- st_read("ign_red_vial/LíneaRed vial provincial.json") |>
mutate(obj = "provincial") |>
select(obj, geometry)
l_terciaria <- st_read("ign_red_vial/LíneaRed vial terciaria.json") |>
mutate(obj = "municipal") |>
select(obj, geometry)
# vector con el orden correcto de las redes viales
obj_orden <- c("nacional", "provincial", "municipal")
# unifico las redes viales
rv <- rbind(l_nacional, l_provincial, l_terciaria) |>
mutate(obj = factor(obj, levels = obj_orden))
# figura ------------------------------------------------------------------
# ubicación de las etiquetas, en 'sf'
coord_etq <- tibble(lon = -63, lat = -45) |>
st_as_sf(coords = c("lon", "lat")) |>
st_set_crs(value = st_crs(p))
# etiquetas
etq_tbl <- tibble(obj = unique(rv$obj)) |>
mutate(geometry = coord_etq$geometry) |>
mutate(label = glue("Red vial\n{toupper(obj)}")) |>
st_as_sf()
# figura
g <- ggplot() +
# red vial
geom_sf(
data = rv, aes(linewidth = obj),
color = "white", show.legend = FALSE) +
# etiqueta
geom_sf_text(
data = etq_tbl, aes(label = label),
color = c3, size = 13, hjust = 0, family = "ubuntu") +
# transformo a Faja POSGAR 2007 faja 4
coord_sf(clip = "off", crs = 5346) +
# especifico los grosores de línea
scale_linewidth_manual(values = c(.5, .25, .1)) +
# faceta
facet_wrap(~ obj, ncol = 3) +
# epígrafe
labs(caption = mi_caption) +
# tema
theme_void() +
theme(
plot.background = element_rect(fill = c1, color = c2, linewidth = 3),
# plot.margin = margin(0, 2.5, 0, 2.5),
plot.margin = margin(0, 4, 0, 4),
plot.title.position = "plot",
plot.title = element_text(
size = 50, color = c3, hjust = .5),
plot.caption = element_markdown(
hjust = .5, size = 15, color = c4, family = "ubuntu",
margin = margin(0, 0, 10, 0)),
strip.text = element_blank()
)
# guardo
ggsave(
plot = g,
filename = "ign_red_vial/viz.png",
width = 60,
height = 44,
units = "cm",
dpi = 300
)
# abro
browseURL("ign_red_vial/viz.png")