Home > database >  Show axis labels of geom_sf in unit metres instead of lat/lon
Show axis labels of geom_sf in unit metres instead of lat/lon

Time:07-08

Problem

I have an sf object in a crs that uses metres as units. I want the axis labels on a ggplot geom_sf to be the asme as in the original geometry - that is metres for my crs, not lat/lon. I don't know how to get rid of the default lat/lon labels.

Example

library(ggplot2)
library(Sf)

data(meuse, package="sp")
meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992)
# Simple feature collection with 155 features and 12 fields
# Geometry type: POINT
# Dimension:     XY
# Bounding box:  xmin: 178605 ymin: 329714 xmax: 181390 ymax: 333611
# Projected CRS: Amersfoort / RD New
# First 3 features:
#   cadmium copper lead zinc  elev       dist   om ffreq soil lime landuse dist.m           geometry
# 1     11.7     85  299 1022 7.909 0.00135803 13.6     1    1    1      Ah     50 POINT (181072 333611)
# 2      8.6     81  277 1141 6.983 0.01222430 14.0     1    1    1      Ah     30 POINT (181025 333558)
# 3      6.5     68  199  640 7.800 0.10302900 13.0     1    1    1      Ah    150 POINT (181165 333537)

st_crs(meuse_sf)$units
# [1] "m"

ggplot()  
  geom_sf(data = meuse_sf, aes(color = cadmium))

enter image description here

CodePudding user response:

You can do this with a coord_sf term...

ggplot()  
  geom_sf(data = meuse_sf, aes(color = cadmium))  
  coord_sf(datum = st_crs(28992))

enter image description here

  • Related