Upload depth_interactive_map_alpha.R
Browse files- depth_interactive_map_alpha.R +24 -27
depth_interactive_map_alpha.R
CHANGED
|
@@ -88,7 +88,7 @@ COL_INFRA <- "#006B82"
|
|
| 88 |
COL_COUNT <- "#374151"
|
| 89 |
|
| 90 |
COL_RED <- "#9E2A3A" # muted brick red
|
| 91 |
-
COL_YEL <- "#
|
| 92 |
COL_AMBER <- "#3A4B5C" # cool slate (point colour)
|
| 93 |
COL_PURPLE <- "#7E4A86" # toned-down mauve
|
| 94 |
COL_GREEN <- "#2D6E54" # forest, lower chroma
|
|
@@ -188,11 +188,11 @@ PATP_DELITO_PAL <- c(
|
|
| 188 |
# threaded through acc_legend_from_spec().
|
| 189 |
PATP_RURAL_LABELS_EN <- c(
|
| 190 |
"Sociales y económicos" = "Social and economic",
|
| 191 |
-
"Carencia o deficiencia en servicios básicos" = "Lack
|
| 192 |
"Caminos, transportes y telecomunicaciones" = "Roads, transport and telecom",
|
| 193 |
"Inseguridad, delincuencia y adicciones" = "Insecurity, crime and addictions",
|
| 194 |
-
"Carencia o deficiencia en la infraestructura educativa y de salud" = "Lack
|
| 195 |
-
"Municipios sin localidades objetivo" = "
|
| 196 |
"Sin problema" = "No problem",
|
| 197 |
"Falta de información / Otro problema" = "Missing information / other",
|
| 198 |
"Riesgos ambientales" = "Environmental risk",
|
|
@@ -201,7 +201,7 @@ PATP_RURAL_LABELS_EN <- c(
|
|
| 201 |
PATP_DELITO_LABELS_EN <- c(
|
| 202 |
"El patrimonio" = "Property",
|
| 203 |
"otros bienes" = "Other property",
|
| 204 |
-
"La vida y la Integridad corporal" = "Life and
|
| 205 |
"múltiples bienes" = "Multiple assets",
|
| 206 |
"La familia" = "Family",
|
| 207 |
"Sin delito" = "No crime",
|
|
@@ -216,14 +216,11 @@ PATP_DELITO_LABELS_EN <- c(
|
|
| 216 |
# silently lumped into an existing bucket. SQL CASE in
|
| 217 |
# WEB_SQL_TEMPLATES$load_infra_pts maps the raw values to these buckets.
|
| 218 |
INFRA_CATS <- c(
|
| 219 |
-
"Shelter"
|
| 220 |
-
"
|
| 221 |
-
"
|
| 222 |
-
"Embassy"
|
| 223 |
-
"
|
| 224 |
-
"Police" = "#9E2A3A", # brick red
|
| 225 |
-
"Health" = "#0987A8", # teal
|
| 226 |
-
"Religious" = "#6B5640", # warm brown
|
| 227 |
"Other" = "#94a3b8" # neutral slate (fallback)
|
| 228 |
)
|
| 229 |
|
|
@@ -1172,7 +1169,7 @@ WEB_SPEC <- list(
|
|
| 1172 |
geom = "polygon", color = "envipe_step", value = "insecurity_perc",
|
| 1173 |
opacity = 0.6, visible = FALSE),
|
| 1174 |
list(id = "routes-lines", type = "line", src = "src_routes",
|
| 1175 |
-
geom = "line", color =
|
| 1176 |
list(id = "viaferrea-lines", type = "line", src = "src_via",
|
| 1177 |
geom = "line", color = "#990f0f", opacity = 0.9, visible = FALSE,
|
| 1178 |
dash = c(4, 2)),
|
|
@@ -1267,11 +1264,11 @@ WEB_SPEC <- list(
|
|
| 1267 |
list(kind = "layer", value = "routes-lines",
|
| 1268 |
label = "Main migration routes through Mexico",
|
| 1269 |
tooltip = "Key routes migrants use to travel through Mexico towards the northern border.",
|
| 1270 |
-
legend = list(type = "line", color = COL_AMBER, label = "
|
| 1271 |
list(kind = "layer", value = "viaferrea-lines",
|
| 1272 |
label = "Railway network",
|
| 1273 |
-
tooltip = "Railway lines used by migrants, including freight routes
|
| 1274 |
-
legend = list(type = "line", color = "#9E2A3A", label = "
|
| 1275 |
list(kind = "layer", value = "pop-choro",
|
| 1276 |
label = "Population (Census 2020)",
|
| 1277 |
tooltip = "Census 2020 population counts. With the grid view off, each municipality shows the sum of its CPV cells (3 sub-types: total, born abroad, resident abroad in 2015). With the grid view on, each rHEALPix cell shows its own value at the active nivel (n4-n7).",
|
|
@@ -4132,7 +4129,7 @@ server <- function(input, output, session) {
|
|
| 4132 |
add_line_layer(
|
| 4133 |
id = "routes-lines",
|
| 4134 |
source = routes_sf,
|
| 4135 |
-
line_color =
|
| 4136 |
line_width = list("interpolate", list("linear"), list("zoom"),
|
| 4137 |
5, 0.5, 10, 2.0),
|
| 4138 |
line_opacity = 0.1, visibility = "none"
|
|
@@ -4354,7 +4351,7 @@ server <- function(input, output, session) {
|
|
| 4354 |
if ("routes-lines" %in% active)
|
| 4355 |
lazy_add_fill("routes", "src_routes", "routes-lines", function(prx, d)
|
| 4356 |
prx |> add_line_layer("routes-lines", source = d,
|
| 4357 |
-
line_color =
|
| 4358 |
# Zoom-interpolated width so the network reads at a national view
|
| 4359 |
# without bloating into a solid mass when zoomed in on a city.
|
| 4360 |
line_width = list("interpolate", list("linear"), list("zoom"),
|
|
@@ -4705,15 +4702,15 @@ server <- function(input, output, session) {
|
|
| 4705 |
# tile the bottom row. Avoids the treemapify dependency.
|
| 4706 |
# Re-toned to the muted Spatial data palette so the treemaps speak the same
|
| 4707 |
# colour language as the map points (no Tailwind-bright sky / red / purple).
|
| 4708 |
-
CAUSE_PAL <- c("Other / unknown" = "#
|
| 4709 |
-
"Drowning" = "#
|
| 4710 |
-
"Harsh environment" = "#
|
| 4711 |
-
"Vehicle accident" = "#
|
| 4712 |
"Violence" = "#9E2A3A") # brick red
|
| 4713 |
# Demographics are nominal (not ordered) and carry no risk valence -- three
|
| 4714 |
# distinct muted hues, avoiding the pink = female / blue = male cliche.
|
| 4715 |
-
DEMO_PAL <- c(Children = "#
|
| 4716 |
-
Female = "#
|
| 4717 |
Male = "#3A4B5C") # slate
|
| 4718 |
|
| 4719 |
# Stacked-bar layout: one horizontal row of segments, widths proportional
|
|
@@ -4751,7 +4748,7 @@ server <- function(input, output, session) {
|
|
| 4751 |
paste0(substr(laid$label, 1L, pmax(1L, max_chars - 1L)), "."),
|
| 4752 |
laid$label)
|
| 4753 |
laid$show_label <- laid$w >= 0.10 # ~ 33 px segments and up
|
| 4754 |
-
laid$show_pct <- laid$w >= 0.
|
| 4755 |
label_df <- laid[laid$show_label, , drop = FALSE]
|
| 4756 |
pct_df <- laid[laid$show_pct, , drop = FALSE]
|
| 4757 |
pct_only <- !pct_df$show_label
|
|
@@ -4805,7 +4802,7 @@ server <- function(input, output, session) {
|
|
| 4805 |
output$migrants_treemap_cause <- renderPlot({
|
| 4806 |
df <- migrants_filtered()
|
| 4807 |
if (is.null(df) || nrow(df) == 0) return(NULL)
|
| 4808 |
-
df$cause_cat[is.na(df$cause_cat) | df$cause_cat == ""] <- "Other
|
| 4809 |
agg <- aggregate(n_dead ~ cause_cat, data = df, FUN = function(x) sum(x, na.rm = TRUE))
|
| 4810 |
summary_df <- data.frame(label = agg$cause_cat,
|
| 4811 |
value = agg$n_dead,
|
|
|
|
| 88 |
COL_COUNT <- "#374151"
|
| 89 |
|
| 90 |
COL_RED <- "#9E2A3A" # muted brick red
|
| 91 |
+
COL_YEL <- "#F5CB5C" # muted ochre (was bright #DEB406)
|
| 92 |
COL_AMBER <- "#3A4B5C" # cool slate (point colour)
|
| 93 |
COL_PURPLE <- "#7E4A86" # toned-down mauve
|
| 94 |
COL_GREEN <- "#2D6E54" # forest, lower chroma
|
|
|
|
| 188 |
# threaded through acc_legend_from_spec().
|
| 189 |
PATP_RURAL_LABELS_EN <- c(
|
| 190 |
"Sociales y económicos" = "Social and economic",
|
| 191 |
+
"Carencia o deficiencia en servicios básicos" = "Lack/deficient basic services",
|
| 192 |
"Caminos, transportes y telecomunicaciones" = "Roads, transport and telecom",
|
| 193 |
"Inseguridad, delincuencia y adicciones" = "Insecurity, crime and addictions",
|
| 194 |
+
"Carencia o deficiencia en la infraestructura educativa y de salud" = "Lack/deficient education and health services",
|
| 195 |
+
"Municipios sin localidades objetivo" = "No target localities (rural)",
|
| 196 |
"Sin problema" = "No problem",
|
| 197 |
"Falta de información / Otro problema" = "Missing information / other",
|
| 198 |
"Riesgos ambientales" = "Environmental risk",
|
|
|
|
| 201 |
PATP_DELITO_LABELS_EN <- c(
|
| 202 |
"El patrimonio" = "Property",
|
| 203 |
"otros bienes" = "Other property",
|
| 204 |
+
"La vida y la Integridad corporal" = "Life and integrity",
|
| 205 |
"múltiples bienes" = "Multiple assets",
|
| 206 |
"La familia" = "Family",
|
| 207 |
"Sin delito" = "No crime",
|
|
|
|
| 216 |
# silently lumped into an existing bucket. SQL CASE in
|
| 217 |
# WEB_SQL_TEMPLATES$load_infra_pts maps the raw values to these buckets.
|
| 218 |
INFRA_CATS <- c(
|
| 219 |
+
"Shelter" = "#3C6E71", # forest green
|
| 220 |
+
"Support (NGO)" = "#F5CB5C", # ochre
|
| 221 |
+
"Support (GOV)" = "#3A4B5C", # slate
|
| 222 |
+
"Embassy / Consulate" = "#4D194D", # deep navy (international protection)
|
| 223 |
+
"Migration office" = "#9E2A3A", # brick red
|
|
|
|
|
|
|
|
|
|
| 224 |
"Other" = "#94a3b8" # neutral slate (fallback)
|
| 225 |
)
|
| 226 |
|
|
|
|
| 1169 |
geom = "polygon", color = "envipe_step", value = "insecurity_perc",
|
| 1170 |
opacity = 0.6, visible = FALSE),
|
| 1171 |
list(id = "routes-lines", type = "line", src = "src_routes",
|
| 1172 |
+
geom = "line", color = "#FFDF9E", opacity = 0.1, visible = FALSE),
|
| 1173 |
list(id = "viaferrea-lines", type = "line", src = "src_via",
|
| 1174 |
geom = "line", color = "#990f0f", opacity = 0.9, visible = FALSE,
|
| 1175 |
dash = c(4, 2)),
|
|
|
|
| 1264 |
list(kind = "layer", value = "routes-lines",
|
| 1265 |
label = "Main migration routes through Mexico",
|
| 1266 |
tooltip = "Key routes migrants use to travel through Mexico towards the northern border.",
|
| 1267 |
+
legend = list(type = "line", color = COL_AMBER, label = "Potential routes following national roads")),
|
| 1268 |
list(kind = "layer", value = "viaferrea-lines",
|
| 1269 |
label = "Railway network",
|
| 1270 |
+
tooltip = "Railway lines used by migrants, including freight routes",
|
| 1271 |
+
legend = list(type = "line", color = "#9E2A3A", label = "Potential routes thought railway", dashed = TRUE)),
|
| 1272 |
list(kind = "layer", value = "pop-choro",
|
| 1273 |
label = "Population (Census 2020)",
|
| 1274 |
tooltip = "Census 2020 population counts. With the grid view off, each municipality shows the sum of its CPV cells (3 sub-types: total, born abroad, resident abroad in 2015). With the grid view on, each rHEALPix cell shows its own value at the active nivel (n4-n7).",
|
|
|
|
| 4129 |
add_line_layer(
|
| 4130 |
id = "routes-lines",
|
| 4131 |
source = routes_sf,
|
| 4132 |
+
line_color = "#FFDF9E",
|
| 4133 |
line_width = list("interpolate", list("linear"), list("zoom"),
|
| 4134 |
5, 0.5, 10, 2.0),
|
| 4135 |
line_opacity = 0.1, visibility = "none"
|
|
|
|
| 4351 |
if ("routes-lines" %in% active)
|
| 4352 |
lazy_add_fill("routes", "src_routes", "routes-lines", function(prx, d)
|
| 4353 |
prx |> add_line_layer("routes-lines", source = d,
|
| 4354 |
+
line_color = "#FFDF9E",
|
| 4355 |
# Zoom-interpolated width so the network reads at a national view
|
| 4356 |
# without bloating into a solid mass when zoomed in on a city.
|
| 4357 |
line_width = list("interpolate", list("linear"), list("zoom"),
|
|
|
|
| 4702 |
# tile the bottom row. Avoids the treemapify dependency.
|
| 4703 |
# Re-toned to the muted Spatial data palette so the treemaps speak the same
|
| 4704 |
# colour language as the map points (no Tailwind-bright sky / red / purple).
|
| 4705 |
+
CAUSE_PAL <- c("Other / unknown" = "#3A4B5C", # neutral slate (COL_COUNT)
|
| 4706 |
+
"Drowning" = "#1B9AAA", # teal-blue / water
|
| 4707 |
+
"Harsh environment" = "#DDDBCB", # ochre / heat
|
| 4708 |
+
"Vehicle accident" = "#F5F1E3", # mauve
|
| 4709 |
"Violence" = "#9E2A3A") # brick red
|
| 4710 |
# Demographics are nominal (not ordered) and carry no risk valence -- three
|
| 4711 |
# distinct muted hues, avoiding the pink = female / blue = male cliche.
|
| 4712 |
+
DEMO_PAL <- c(Children = "#DDDBCB", # ochre
|
| 4713 |
+
Female = "#1B9AAA", # mauve
|
| 4714 |
Male = "#3A4B5C") # slate
|
| 4715 |
|
| 4716 |
# Stacked-bar layout: one horizontal row of segments, widths proportional
|
|
|
|
| 4748 |
paste0(substr(laid$label, 1L, pmax(1L, max_chars - 1L)), "."),
|
| 4749 |
laid$label)
|
| 4750 |
laid$show_label <- laid$w >= 0.10 # ~ 33 px segments and up
|
| 4751 |
+
laid$show_pct <- laid$w >= 0.08
|
| 4752 |
label_df <- laid[laid$show_label, , drop = FALSE]
|
| 4753 |
pct_df <- laid[laid$show_pct, , drop = FALSE]
|
| 4754 |
pct_only <- !pct_df$show_label
|
|
|
|
| 4802 |
output$migrants_treemap_cause <- renderPlot({
|
| 4803 |
df <- migrants_filtered()
|
| 4804 |
if (is.null(df) || nrow(df) == 0) return(NULL)
|
| 4805 |
+
df$cause_cat[is.na(df$cause_cat) | df$cause_cat == ""] <- "Other/unknown"
|
| 4806 |
agg <- aggregate(n_dead ~ cause_cat, data = df, FUN = function(x) sum(x, na.rm = TRUE))
|
| 4807 |
summary_df <- data.frame(label = agg$cause_cat,
|
| 4808 |
value = agg$n_dead,
|