Get lost

Day 10 of 30DayMapChallenge
R
30DayMapChallenge
datavisualization
spatial
Author

Michaël

Published

2022-11-10

Modified

2024-11-24

Day 10 of 30DayMapChallenge: « bad map » (previously).

Just resampling…

library(tidyverse)
library(sf)
library(glue)
library(ggspatial)
library(ggrepel)
library(rnaturalearth)

set.seed(4326)

# final projection
map_proj <- "EPSG:2154"

# cities (randomized)
pref <- read_sf("~/data/adminexpress/adminexpress_cog_simpl_000_2022.gpkg", 
                layer = "commune") |> 
  filter(insee_reg > "06", 
         str_detect(statut, "Préfecture de région|Capitale"))  |>
  mutate(nom = sample(nom)) |> 
  st_point_on_surface()

# départements
fr <- read_sf("~/data/adminexpress/adminexpress_cog_simpl_000_2022.gpkg",
              layer = "departement") |> 
  filter(insee_reg > "06") |> 
  st_transform(map_proj)

# basemap
countries <- ne_countries(50, returnclass = "sf") |> 
  filter(admin != "France", 
         continent == "Europe")
fr |> 
  ggplot() +
  geom_sf(data = countries, color = "grey20", fill = "grey12") + 
  geom_sf(color = "grey", fill = "lightgrey") + 
  geom_sf(data = pref, color = "black", size = 1) +
  geom_text_repel(data = pref, 
                  aes(label = nom, geometry = geom), 
                  stat = "sf_coordinates", 
                  size = 3,
                  bg.color = "#ffffff66",
                  bg.r = 0.2 ) +
  coord_sf(xlim = st_bbox(fr)[c(1, 3)],
           ylim = st_bbox(fr)[c(2, 4)],
           crs = map_proj) +
  labs(title = "France métropolitaine",
       subtitle = "Get lost",
       x = "",
       y = "",
       caption = glue("data : based on IGN Adminexpress
                      proj.: {format(st_crs(map_proj))}
                      r.iresmi.net - {Sys.Date()}")) +
  theme(plot.background = element_rect(fill = "grey10", color = NA),
        panel.background = element_rect(fill = "grey10", color = NA),
        panel.grid = element_line(color = "grey15"),
        plot.title = element_text(color = "grey90", family = "Waree"),
        plot.subtitle = element_text(color = "grey90"),
        plot.caption = element_text(color = "grey60", size = 6))