Mapping an sf object with geom_sf

132 views
Skip to first unread message

Manuel Spínola

unread,
Mar 11, 2017, 9:52:32 AM3/11/17
to ggplot2
Dear list members,

I am trying to map an sf projected (utm) spatial object with geom_sf.

cr_sf <- read_sf("cr_crtm05.gpkg", layer = "cr_crtm05")

Reading layer `cr_crtm05' from data source `C:\Users\mspin\Dropbox\Proyectos_en_R\Sinac\cr_crtm05.gpkg' using driver `GPKG'
Simple feature collection with 1 feature and 6 fields
geometry type:  POLYGON
dimension:      XY
bbox:           xmin: 286586.4 ymin: 889526.4 xmax: 658487.2 ymax: 1241338
epsg (SRID):    NA
proj4string:    +proj=tmerc +lat_0=0 +lon_0=-84 +k=0.9999 +x_0=500000 +y_0=0 +ellps=WGS84 +units=m +no_defs

When I plot with ggplot2, the coordinates are in geographic coordinates, not in utm as is the source map

ggplot() + geom_sf(data = cr_sf, fill = "darkblue") + coord_sf(crs = st_crs(cr_sf))

Is it possible to keep the map in the projected utm crs? 

--
Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspi...@una.cr
mspin...@gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río
Institutional website: ICOMVIS

Hadley Wickham

unread,
Mar 15, 2017, 4:57:05 PM3/15/17
to Manuel Spínola, ggplot2
On Sun, Mar 12, 2017 at 3:52 AM, Manuel Spínola <mspin...@gmail.com> wrote:
> Dear list members,
>
> I am trying to map an sf projected (utm) spatial object with geom_sf.
>
> cr_sf <- read_sf("cr_crtm05.gpkg", layer = "cr_crtm05")
>
> Reading layer `cr_crtm05' from data source
> `C:\Users\mspin\Dropbox\Proyectos_en_R\Sinac\cr_crtm05.gpkg' using driver
> `GPKG'
> Simple feature collection with 1 feature and 6 fields
> geometry type: POLYGON
> dimension: XY
> bbox: xmin: 286586.4 ymin: 889526.4 xmax: 658487.2 ymax: 1241338
> epsg (SRID): NA
> proj4string: +proj=tmerc +lat_0=0 +lon_0=-84 +k=0.9999 +x_0=500000 +y_0=0
> +ellps=WGS84 +units=m +no_defs
>
> When I plot with ggplot2, the coordinates are in geographic coordinates, not
> in utm as is the source map
>
> ggplot() + geom_sf(data = cr_sf, fill = "darkblue") + coord_sf(crs =
> st_crs(cr_sf))

Looking at the comment above, I see "+proj=tmerc", which suggests the
source map is projected. If you want it in UTM, provide the
appropriate crs to coord_sf().

Hadley

--
http://hadley.nz
Reply all
Reply to author
Forward
0 new messages