Skip to content
Prev 25430 / 29559 Next

How to draw a legend when plotting sf (simple feature) objects

On 26/02/17 13:23, Manuel Sp?nola wrote:
You're in base plot, so at this moment you can add elements
incrementally to the plot, see e.g. ?legend.

I have no plans of making this easy or automatic, because I don't think
that base plot is the right place for it (although packages raster,
spatstat and fields try hard), but would happily consider contributions.

geom_sf in ggplot2 (now in sf branch on github) will follow up
sp::spplot for sf objects; see e.g.

https://github.com/edzer/sfr/issues/88#issuecomment-276738460

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc) + geom_sf(aes(fill = SID79))

Trying this with the gpkg you read in above fails for me; it looks like
ggplot now wrongly assumes that geometry columns are always called
`geometry' (despite the docs), which is not the case.