My Authors
Read all threads
Spatial plotting just improved a lot in the development version of ggplot2. In a nutshell, you can now mix and match regular geoms with `geom_sf()` and `coord_sf()`. If you're doing any geospatial plotting, please test this out. 1/n
#rstats #ggplot2 Image
The key idea is that `coord_sf()` now has a default coordinate system that it uses for any objects that are not sf (i.e., don't come with their own coordinate information). The default is longitude/latitude, which makes it super easy to, for example, mark a specific location. 2/n ImageImage
This works with essentially any geom, e.g., we can mark a couple of cities and draw an enclosing polygon. 3/n ImageImage
As a consequence, we can now use `annotation_map()` in combination with `geom_sf()` and `coord_sf()`. `annotation_map()` draws regular polygons in long/lat space. 4/n ImageImage
Limits are assumed to be in the default coordinate system, so we can now provide them as long/lat. 5/n ImageImage
There's an important safety net when you don't want any of this: Set `default_crs = NULL` and you revert to the old behavior. For example, then you have to set limits in transformed coordinates. 6/n ImageImage
If you find yourself having to work in projected coordinates, you may find the function`sf_transform_xy()` useful. It can transform regular data frames of coordinates from one coordinate system to another. 7/n Image
(This function is used internally by ggplot2 to calculate the coordinate transformations. It turns the data frame into sf points and then transforms them using the sf::st_transform() function.) 8/n
That's it for now. If you run into any issues, please ping me or file an issue on github. I'll close with one last example, using ggrepel and an unusual projection from the top of the pole. 9/9 ImageImage
Missing some Tweet in this thread? You can try to force a refresh.

Keep Current with Claus Wilke

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!