Skip to contents

coord_sf() is the coordinate system for mark_sf() maps. Before scale training it reprojects every sf layer to a common CRS (via sf::st_transform()), so the renderer only ever sees projected Cartesian coordinates, and it locks the panel aspect ratio so the map is not stretched: 1 for a projected CRS, and the equirectangular correction 1/cos(mean_latitude) for unprojected longitude/latitude data.

Usage

coord_sf(
  plot,
  crs = NULL,
  xlim = NULL,
  ylim = NULL,
  graticule = FALSE,
  graticule_labels = TRUE
)

Arguments

plot

A PlotSpec.

crs

Target coordinate reference system to project all layers into (anything sf::st_crs() accepts, e.g. an EPSG code, "OGC:CRS84", or a proj/WKT string). NULL (default) uses the CRS of the first sf layer. For guaranteed longitude/latitude order, use "OGC:CRS84" rather than EPSG:4326. For choropleths, prefer an equal-area CRS.

xlim, ylim

Length-2 view-window limits in the target CRS, or NULL.

graticule

Draw meridians and parallels behind the map. FALSE (default) draws none; TRUE picks round longitude/latitude breaks automatically; a list list(lon = , lat = ) sets the breaks explicitly (in degrees). For a projected CRS the lines are reprojected and therefore curved; for unprojected longitude/latitude they are straight.

graticule_labels

Label the graticule lines with their degree values (default TRUE); ignored when graticule is FALSE.

Value

The modified PlotSpec.

Details

sf is an optional dependency (in Suggests); coord_sf() errors with an install hint if it is not available at render time.

Examples

if (FALSE) { # \dontrun{
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
vplot(nc) |> mark_sf(fill = BIR74) |> coord_sf(crs = "OGC:CRS84")
vplot(nc) |> mark_sf(fill = BIR74) |> coord_sf(crs = 3857, graticule = TRUE)
} # }