Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sf objects for maps? #210

Open
etiennebacher opened this issue Aug 30, 2024 · 2 comments
Open

Support sf objects for maps? #210

etiennebacher opened this issue Aug 30, 2024 · 2 comments

Comments

@etiennebacher
Copy link
Contributor

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 TRUE

nc <- 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).

@etiennebacher etiennebacher changed the title Support for sf objects for maps? Support sf objects for maps? Aug 30, 2024
@etiennebacher
Copy link
Contributor Author

Just to clarify, in the end tinyplot would call sf:::plot.sf

@grantmcdermott
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants