Hey #spatial #R folks, is it possible to extract geometries from #ggplot as files? That is, the point, line, and polygon geometries in the graphs to #geopackage or #shapefile etc.

It is possible with #seaborn and #matplotlib, but that's Python not R. There's a nice and lightning fast #EdgeBundling technique in the newest ggplot, which is very promising for the #visualization of massive #mobility data.

There is also something in #HoloViews but I do not understand that library at all.

@waeiski you might start and see what luck you have with layer_data()
@waeiski ... which shows the underlying data for plotting a specified layer in the last plot. layer_date(i = 2) if the second layer is the one you are interested in.

@EvaMaeRey @defuneste Thank you for the inputs.

One would think this would be straight-forward, plotting anything requires the use of coordinates, no matter if they represent a value range, or geographical coordinates, so extracting the geometric shape should retain the coordinate information, which should be rather trivial to turn into a spatial file with a CRS.

@waeiski @EvaMaeRey @defuneste that's what layer_data does. For a layer added with geom_sf, you get the geometric features in `sf` format which you can write to any OGR format with `st_write`. Couldn't be much more straightforward unless I'm misunderstood your exact problem...
@geospacedman @waeiski @defuneste I've run into it defying my expectations with ggrepel, thinking I could extract the rendered positions, but that failed... thus a little hesitation. 🤞 for this case!

@geospacedman @EvaMaeRey @defuneste Thank you! I will try this.

You've understood it correctly. My posts/responses may have betrayed my low skill level in R, sorry for any confusion!

@waeiski I think R people able to help will be in #rstats or #rSpatial. I don't know much about extrating geometries, but ggplot is not for simple feature manipulation. These packages might be better for it: https://github.com/rspatial
Good luck!
rspatial

The R packages terra, luna, raster, geosphere and friends. See "github.com/r-spatial" for "sf" c.s. - rspatial

GitHub
@waeiski it is… awkward.. but can be done in a couple steps. See the answer here. https://stackoverflow.com/questions/46248061/save-a-ggplot2-coord-map-chart-in-shapefile
Save a ggplot2 coord_map() chart in shapefile

i need to export a contour map in CARTO (aka cartodb), so i'm trying to save this stat2density chart in a geodata file format like shapefile or geojson. I'm able to save it in SVG with ggsave, but ...

Stack Overflow

@waeiski the "spatial leaders" in R shat in ggplot when it was born, poisoning the well

Its construction semantics are amazing and perfect for spatial, but polygons at the time were based on shape files and GG copped heat for using the same idea ...

layer_data should be enough, wrap with the constructers of {wk} or {sfheaders}