# BASE MAP ------------------------------------------------------
# Test out the map
g_map <- ggplot() +
geom_spatraster(data = elevation_raster) +
geom_sf(
data = country_map,
fill = "transparent",
linewidth = 0.7,
colour = text_col
) +
geom_sf(
data = df,
mapping = aes(size = crowd_size),
alpha = 0.2,
colour = mypal[3]
) +
scale_size_continuous(
range = c(5, 40)
) +
scale_fill_gradient2(
low = "white", high = "grey50",
na.value = "white"
) +
ggnewscale::new_scale("size") +
geom_sf_text(
data = city_labels,
mapping = aes(label = admin2, size = n),
colour = text_col,
family = "body_font"
) +
scale_size_continuous(
range = c(bts / 5, bts / 2)
) +
guides(
size = "none",
fill = "none",
new_size = "none",
size_new = "none"
) +
coord_sf(
crs = "EPSG:3857"
) +
ggthemes::theme_map(
base_family = "body_font",
base_size = bts
) +
theme(
plot.margin = margin(10,0,0,0, "mm"),
legend.position = "none"
)
# INSET 1: PACK CIRCLES -----------------------------
g_inset_1 <- ggplot() +
geom_polygon(
data = incidents_circles,
mapping = aes(x, y, group = id),
fill = mypal[3],
colour = bg_col
) +
geom_text(
data = incidents_by_region |> slice_max(order_by = n, n = 6),
mapping = aes(
x, y,
label = paste0(str_wrap(admin1, 7), "\n",
round(prop * 100, 0), " %"),
size = prop
),
colour = bg_col,
lineheight = 0.3,
family = "body_font"
) +
scale_size_continuous(range = c(bts/10, bts/5)) +
coord_equal() +
guides(size = "none") +
labs(title = "% incidents by region") +
theme_void(
base_size = bts,
base_family = "body_font"
) +
theme_custom()
# INSET 2: BAR CHART ------------------------------
g_inset_2 <- df2 |>
ggplot(
mapping = aes(
x_var, n
)
) +
geom_col(
fill = mypal[2],
colour = "transparent"
) +
geom_col(
fill = mypal[4],
colour = "transparent",
width = 10
) +
geom_text(
data = slice_max(df2, order_by = n, n = 5),
mapping = aes(
label = paste0(event_month, "\n", event_year)
),
lineheight = 0.3,
family = "body_font",
nudge_y = 10,
vjust = 0,
colour = text_col,
size = bts / 4
) +
scale_x_date(
breaks = make_date(year = 2020:2024, month = 6),
date_labels = "%Y",
date_minor_breaks = "1 month",
# minor_breaks = make_date(
# year = 2020:2024,
# month = rep(1:12, 5),
# day = 15
# )
) +
scale_y_continuous(
breaks = seq(0, 800, 200),
expand = expansion(c(0,0.1))
) +
labs(
x = NULL, y = NULL,
title = "Monthly Incidents"
) +
theme_minimal(
base_family = "body_font",
base_size = bts
) +
theme(
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.line = element_line(colour = text_hil, linewidth = 1),
panel.grid.minor.y = element_blank(),
panel.grid.major.y = element_line(
linewidth = 0.2,
colour = text_hil
),
axis.ticks.x = element_line(
colour = text_hil
),
axis.ticks.length.x = unit(2, "mm")
) +
theme_custom() +
theme(
axis.text = element_text(
margin = margin(0,0,0,0, "mm"),
hjust = 0.5
),
axis.ticks.length.y = unit(0, "mm")
)
# INSET 3 - ISLAS CANARIAS -------------------
g_inset_3 <- ggplot() +
geom_sf(
data = islas_canarias,
fill = "transparent"
) +
geom_sf(
data = df_islas_canarias,
mapping = aes(size = crowd_size),
alpha = 0.2,
colour = mypal[3]
) +
scale_size_continuous(
range = c(1, 30)
) +
geom_sf_text(
data = text_labels_islas_canarias,
mapping = aes(label = city),
colour = text_hil,
family = "body_font",
size = bts / 5
) +
scale_fill_gradient2(
low = "white", high = "grey50",
na.value = "white"
) +
guides(
size = "none",
fill = "none"
) +
coord_sf(
crs = "EPSG:3857"
) +
labs(
title = "Islas Canarias"
) +
ggthemes::theme_map(
base_size = bts,
base_family = "body_font"
) +
theme_custom()
# INSET 4: Road Network --------------------------------
g_inset_4 <- ggmap(country_roads) +
ggthemes::theme_map(
base_size = bts,
base_family = "body_font"
) +
labs(title = paste0("Road Network in ", selected_country)) +
theme_custom()