Skip to content

Fixes for ggplot2 >3.1.0 #1481

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

Merged
merged 3 commits into from
Mar 11, 2019
Merged

Fixes for ggplot2 >3.1.0 #1481

merged 3 commits into from
Mar 11, 2019

Conversation

cpsievert
Copy link
Collaborator

Closes #1457.

This was a fun 🐛 to track down 🔍

Background

Typically, when ggplotly() translates a layer, it prefixes the class of the data with "Geom*". This is what allows geom2plotly() to work off S3 methods. The aes2plotly() function also uses this class to query the Geom's default aesthetics from ggplot2's namespace.

The issue

To translate the graticule that comes with geom_sf()/coord_sf(), I call geom2trace.GeomPath() in a fairly un-standard way:

https://github.com/ropensci/plotly/blob/4473d6454f01825e8f15783e670e6fffb017e123/R/ggplotly.R#L611

That ends up calling this code, and in this case, the value of geom is data.frame.

https://github.com/ropensci/plotly/blob/4473d6454f01825e8f15783e670e6fffb017e123/R/layers2traces.R#L1003

As of tidyverse/ggplot2@92d2777, ggplot2 now defines data.frame in it's namespace, so ggfun(geom)$default_aes no longer returns NULL (in fact, it errors out)

Copy link
Contributor

@schloerke schloerke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to else and store result of ggfun(geom) in the else block

@cpsievert cpsievert changed the title Be more careful about searching for default aesthetics Fixes for ggplot2 >3.1.0 Mar 11, 2019
@cpsievert
Copy link
Collaborator Author

@schloerke turns out there was another issue contributing to #1457, introduced by tidyverse/ggplot2#2875.

That ggplot2 PR introduced a new Layer method, which introduced changes ggplot_build(), that ggplotly() needs to directly replicate -- done in 37b79e9

@cpsievert cpsievert merged commit cd16455 into master Mar 11, 2019
@cpsievert cpsievert deleted the sf-fix branch March 28, 2019 19:30
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

Successfully merging this pull request may close these issues.

ggplotly give error when used with sf
2 participants