-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2023_30daymapchallenge_day01_points.R
96 lines (89 loc) · 3.98 KB
/
2023_30daymapchallenge_day01_points.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
library(tidyverse)
library(sf)
library(ggtext)
library(sysfonts)
library(showtextdb)
library(showtext)
# = = GOOGLE FONTS = = #
title_font <- "Roboto Condensed"
subtitle_font <- "Cabin"
font_add_google(title_font, title_font)
font_add_google(subtitle_font, subtitle_font)
showtext_auto()
# = = LOAD DATA = = #
# Puntos de las estaciones de Metrobus de la CDMX
sf_estaciones_mb <- read_sf("./data/mb_shp/Metrobus_estaciones.shp") %>% janitor::clean_names() # nolint
# Manzanas de la CDMX
sf_manzanas_cdmx <- read_sf("./data/manzanas_cdmx_2022.geojson") %>% janitor::clean_names() # nolint
# = = DATA PROCESSING AND TRANSFORMATION = = #
# - - Colores y transbordos de los puntos - - #
sf_estaciones_mb_interes <- sf_estaciones_mb %>%
mutate(
color_id = case_when(
linea == "01" ~ "#B32118",
linea == "02" ~ "#893893",
linea == "03" ~ "#78A331",
linea == "04" ~ "#F68E1C",
linea == "05" ~ "#06357A",
linea == "06" ~ "#E83E97",
linea == "07" ~ "#017337",
.default = "#222222"
)
) %>%
select(nombre, linea, tipo, color_id) %>%
replace_na(list(tipo = "Otro"))
# = = DATAVIS = = #
# Marcar transbordos entre diferentes lineas
vec_estaciones_transbordos_lineas <- sf_estaciones_mb_interes %>% # nolint
filter(tipo == "Transbordo") %>%
group_by(nombre) %>%
filter(n() > 1) %>%
ungroup() %>%
distinct(nombre, linea) %>%
count(nombre, sort = TRUE) %>%
filter(n > 1) %>%
pull(nombre)
p1 <- ggplot() +
geom_sf(
data = sf_manzanas_cdmx,
mapping = aes(fill = tipomza),
linewidth = 0, color = "white", alpha = 1) +
geom_sf(
data = sf_estaciones_mb_interes,
mapping = aes(
color = color_id,
shape = if_else(nombre %in% vec_estaciones_transbordos_lineas, 17, 16), # nolint
size = if_else(nombre %in% vec_estaciones_transbordos_lineas == "Transbordo", 3, 1)), # nolint
) +
scale_color_identity() +
scale_shape_identity() +
scale_size_identity() +
scale_fill_manual(
values = MoMAColors::moma.colors("Picabia", n = 45, direction = 1)[35:45]) +
labs(title = "#30DayMapChallenge. Day 1: Points",
subtitle = "Estaciones _(círculos)_ y Transbordos _(triángulos)_ del Metrobús de la CDMX<br>El color indica la línea: <span style='color:#B32118;'>1</span>, <span style='color:#893893;'>2</span>, <span style='color:#78A331;'>3</span>, <span style='color:#F68E1C;'>4</span>, <span style='color:#06357A;'>5</span>, <span style='color:#E83E97;'>6</span> y <span style='color:#017337;'>7</span>", # nolint
caption = '<strong>Datos:</strong> <em>Ubicación de líneas y estaciones del Metrobús</em> a través del <strong>Portal de Datos Abiertos de la Ciudad de México</strong>. <em>Marco Geoestadístico de México (2022)</em> a través del <strong>INEGI</strong><br><br><em>Isaac Arroyo (@unisaacarroyov)</em>') + # nolint
theme_void() +
theme(
plot.background = element_rect(color = "#222222", fill = "#222222"),
legend.position = "none",
plot.title.position = "plot",
plot.caption.position = "plot",
plot.title = element_textbox(color = "white",
width = unit(8, "in"),
size = 80,
family = title_font, face = "bold"),
plot.subtitle = element_textbox(colour = "white",
width = unit(8, "in"),
size = 40, lineheight = 0.5,
family = subtitle_font),
plot.caption = element_textbox(color = "white",
width = unit(8, "in"),
margin = margin(t = -0.75, unit = "in"),
size = 30, lineheight = 0.4,
family = subtitle_font,
hjust = 0)
)
tgutil::ggpreview(p1, width = 8, height = 10, units = "in", dpi = 300)
ggsave(p1, width = 8, height = 10, units = "in", dpi = 300,
filename = "./maps/2023_30daymapchallenge_day01_points.png")