[R-sig-Geo] How to draw a legend when plotting sf (simple feature) objects
Manuel Spínola
mspinola10 at gmail.com
Sun Feb 26 19:17:25 CET 2017
Thank you very much Edzer,
it works for me:
> ggplot(nc) + geom_sf(aes(fill = SID79))
Warning message:
st_crs<- : replacing crs does not reproject data; use st_transform for that
2017-02-26 11:46 GMT-06:00 Edzer Pebesma <edzer.pebesma at uni-muenster.de>:
>
>
> On 26/02/17 13:23, Manuel Spínola wrote:
> > Dear list members,
> >
> > How can I draw a legend when plotting an sf (simple feature) object.
> >
> > nc = st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE)
> >
> > plot(nc["SID79"])
> >
>
> 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.
> --
> Edzer Pebesma
> Institute for Geoinformatics (ifgi), University of Münster
> Heisenbergstraße 2, 48149 Münster, Germany; +49 251 83 33081
> Journal of Statistical Software: http://www.jstatsoft.org/
> Computers & Geosciences: http://elsevier.com/locate/cageo/
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola at una.cr <mspinola at una.ac.cr>
mspinola10 at gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río <https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list