Glad the scale bar function from ggspatial is still useful!

I'm not sure that when I put that warning in that I anticipated the number of use-cases where this warning would be emitted. On most maps of large-scale areas you see in the wild, the scale bar will be wildly inaccurate for some places on the map and for most maps this is OK (unless your map is quite literally claiming to be a map of the distance between x and x, for example). The function of the scale bar is often to communicate order of magnitude, or often just has to exist as a requirement for a publication style guide.

What I'm getting at is that...I wrote that warning and I ignore it all the time :)

All the best,

-dewey

On 2025-07-13 10:22, Micha Silver via R-sig-Geo wrote:
--
Micha Silvercell: +972-523-665918

On Sunday, 13 July 2025 at 15:41, Gabriel Cotlier <[email protected]> wrote:

Yes is correct. Using CRS 3587 would correct this distortion?
Thanks a lot.

I don't think so
Check here:
https://epsg.io/3857

If it's important to keep distances accurate, you should look for an equidistant projection for your area. Maps of Europe are typically projected to EPSG:3035 which is equal area, not equidistant, but it's pretty close, and widely accepted.

On Sun, Jul 13, 2025 at 5:48 AM Micha Silver <[[email protected]](mailto:micha_silver%[email protected])> wrote:

--
Micha Silvercell: +972-523-665918

On Saturday, 12 July 2025 at 23:35, Gabriel Cotlier <[email protected]> wrote:

Dear Micha,
Thank you very much for the tip. I worked out, but I am concerned about the warning that appears:

I assume that is because you are using WGS84 long/lat. So there is a difference in distances E-W vs N-S. For example, in S. Spain 1 degree N-S is about 110 km while 1 degree E-W is about 90 km.

Scale on map varies by more than 10%, scale bar may be inaccurate

On Sat, Jul 12, 2025 at 5:01 PM Micha Silver <[[email protected]](mailto:micha_silver%[email protected])> wrote:

--
Micha Silver
cell: +972-523-665918

On Saturday, 12 July 2025 at 16:47, Gabriel Cotlier <[email protected]> wrote:

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

You might consider the `ggspatial` package that has a function: `annotation_scale()`

https://paleolimbot.github.io/ggspatial/reference/annotation_scale.html


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")

[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to