Reputation: 2493
I would like to find out the exact map scale in m or km of my SpatialPolygons
object and plot it on my spplot
so that the reader gets an idea about the distances.
That means that I would like to find out what number to put in for the ???
in the plot.
library("sp")
library("CARBayes")
data("spatialhousedata")
proj4string(spatialhousedata) <- CRS("+proj=cass +lat_0=52.41864827777778 +lon_0=13.62720366666667
+x_0=40000 +y_0=10000 +datum=potsdam +units=m +no_defs
+ellps=bessel +towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7 ")
scalebar=list("SpatialPolygonsRescale", layout.scale.bar(),
offset = c(225000,647000), scale = 10000, fill=c("transparent","black"))
text1=list("sp.text", c(225000,649000), "0")
text2=list("sp.text", c(230000,649000), "??? m")
spplot(spatialhousedata, "price",
sp.layout=list(scalebar, text1, text2))
Maybe something with sp::coordinates
or Imap::gdist
? Any prior reprojection of the SpatialPolygons
necessary to find this out?
Upvotes: 3
Views: 808
Reputation: 4121
Your data are projected (try is.projected(spatialhousedata)
); I would go for the
text2=list("sp.text", c(235000,649000), "10 km")
the scale bar can be confirmed by drawing the axis scales:
spplot(spatialhousedata, "price", scales = list(draw=TRUE),
sp.layout=list(scalebar, text1, text2))
Upvotes: 3