Closed kbzsl closed 2 years ago
This is a projection issue. basemap
returns maps in the Web Mercator proejction (EPSG: 3857), the standard used by many tiling services (see section Value under ?basemap
). That means you are trying to plot two objects with different CRSs on top of each other.
Just transform your polygon to Web Mercator first, e.g. by extracting the CRS form the pulled map like this
bp_margit <- st_transform(
bp_margit,
crs = st_crs(basemap_stars(bp_margit))
)
or manually setting EPSG 3857
bp_margit <- st_transform(bp_margit, crs = st_crs(3857)
)
before plotting
ggplot() +
basemap_gglayer(bp_margit) +
geom_sf(data = bp_margit, color = "red") +
coord_sf() +
scale_fill_identity()
Sorry, for my novice question, but I cannot figure out what’s gone wrong when combining a raster background and other sf objects using the
basemaps
andggplot2
packages. Thank you.Here is my code, it should draw a square around Margaret Island, Budapest