You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @grantmcdermott, @vincentarelbundock and @zeileis, I'm just wondering whether support for sf objects is on the roadmap. ggplot2 can be quite slow when drawing maps with several elements (say all the US counties + fill by variable + points). To clarify, creating the map is not slow but printing it can easily take 15-20 seconds or more and I'm wondering if a base plot would be faster for this.
A complete support would probably be complicated, but here's a very simple example:
library(ggplot2)
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUEnc<-sf::st_read(system.file("shape/nc.shp", package="sf"), quiet=TRUE)
ggplot(nc) +
geom_sf(aes(fill=AREA))
nc[, "AREA", drop=FALSE] |>
plot()
Being able to do plt(~ AREA, fill = "by", type = "map") would be great (contrarily to the syntax for density plots, we'd only need to have one variable in the formula here).
Native sf support is something I'd love to support. See #159 (comment) for a proof of concept.
One annoyance we'd have to figure out is color scaling for continuous grouping variables, since polypaths aren't currently compatible with our gradient legend logic. I have an idea for a workaround, but won't have time to look into this properly for the next few weeks.
Thanks for putting it on my (our!) radar again.
Reacted by Etienne Bacher, Edzer Pebesma and Achim Zeileis
@grantmcdermott Interesting! Note that mapsf is also base graphics. Further, classInthttps://cran.r-project.org/package=classInthttps://r-spatial.github.io/classInt/ is used by sf, tmap and mapsf and others for typically cartographic assignment of classes to continuous variables - mapsf has a couple of styles extending those in classInt. If need be, classInt could be modernised (originally written after a workshop almost 20 years ago). Might it help wrt. the annoyance you raise? Could I help?
I still hope to add sf support here (and #433 will be an important step towards that)... But I recently learned about mapsf, which looks like a fantastic option for base graphics maps: https://riatelab.github.io/mapsf/#/
Activity
[-]Support for `sf` objects for maps?[/-][+]Support `sf` objects for maps?[/+]etiennebacher commentedon Aug 30, 2024
Just to clarify, in the end
tinyplotwould callsf:::plot.sfgrantmcdermott commentedon Aug 30, 2024
Native sf support is something I'd love to support. See #159 (comment) for a proof of concept.
One annoyance we'd have to figure out is color scaling for continuous grouping variables, since polypaths aren't currently compatible with our gradient legend logic. I have an idea for a workaround, but won't have time to look into this properly for the next few weeks.
Thanks for putting it on my (our!) radar again.
edzer commentedon Feb 24, 2025
Happy to help here, let me know!
grantmcdermott commentedon Feb 25, 2025
Thanks @edzer, I'm hoping to dive back into this in a few weeks.
rsbivand commentedon Feb 25, 2025
@grantmcdermott Interesting! Note that
mapsfis also base graphics. Further,classInthttps://cran.r-project.org/package=classInt https://r-spatial.github.io/classInt/ is used bysf,tmapandmapsfand others for typically cartographic assignment of classes to continuous variables -mapsfhas a couple of styles extending those inclassInt. If need be,classIntcould be modernised (originally written after a workshop almost 20 years ago). Might it help wrt. the annoyance you raise? Could I help?rsbivand commentedon Feb 25, 2025
For reference if anyone has time: https://github.com/rsbivand/eqc23_talk, https://rsbivand.github.io/eqc23_talk/ and links in the slides, especially https://magrit-formations.github.io/discretisation (@rCarto). Of course https://r-spatial.org/book/08-Plotting.html too.
grantmcdermott commentedon Jul 12, 2025
I still hope to add
sfsupport here (and #433 will be an important step towards that)... But I recently learned aboutmapsf, which looks like a fantastic option for base graphics maps: https://riatelab.github.io/mapsf/#/rCarto commentedon Jul 15, 2025
I'm glad to hear that :-) I appreciate the "tiny" approach. Happy to help or discuss
mapsffeatures if you'd like.