Get lost
[This article was first published on r.iresmi.net, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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))
To leave a comment for the author, please follow the link and comment on their blog: r.iresmi.net.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.