Hello,
I would like to ask for help to add a scale bar to the following map below.
Thanks a lot in advance.
Kind regards,
Gabriel
library(ggplot2)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
# Get world map data
world <- ne_countries(scale = "medium", returnclass = "sf")
# Define the bounding box for Europe
europe_extent <- st_bbox(c(xmin = -12, xmax = 35, ymin = 30, ymax = 72),
crs = st_crs(4326))
# Filter for Europe, then for Italy and Iberian Peninsula
europe <- st_crop(world, europe_extent)
italy_and_iberian <- europe[europe$name %in% c("Spain", "Portugal",
"Italy"),]
# Load another shapefile
# Replace "path/to/your/shapefile.shp"
A <- st_read("path/to/your/shapefile1.shp" )
B <- st_read("path/to/your/shapefile2.shp" )
sq1 <- st_read("path/to/your/shapefile3.shp" )
sq2 <- st_read("path/to/your/shapefile4.shp" )
# Plot the map with the added shapefile
ggplot(data = europe) +
geom_sf(fill = "lightgray") + # Background map
geom_sf(data = italy_and_iberian, fill = "skyblue") + # Highlighted areas
geom_sf(data = A, fill = "lightgreen") + # Added shapefile
geom_sf(data = B, fill = "lightblue") + # Added shapefile
geom_sf(data = sq1, fill =NA, color="red", lwd=0.5) + # Added shapefile
geom_sf(data = sq2, fill=NA, color ="red", lwd=0.5) + # Added shapefile
coord_sf(xlim = c(-12, 35), ylim = c(30, 72), expand = FALSE) + # Set map
boundaries.
theme_bw() +
labs(title = "Italian, Iberian in Europe")