-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Adding Layout
slot to ggplot object
#5576
Adding Layout
slot to ggplot object
#5576
Conversation
Thanks for the PR! I've given this some thought and I've come to agree that it would be useful for developers to implement their own Layout strategies. However, I've come to doubt that exporting
|
Lets game it out a bit, so instead of exporting Lets then assume the create_layout <- function(layer = Layer, facet, coord) {
ggproto(NULL, layer, facet = facet, coord = coord)
} and in practice, it would be called like so in ggplot_build.ggplot <- function(plot){
...
layout <- create_layout(plot$layout, plot$facet, plot$coord)
...
} and then developers who may want to extend the ggplot_build.my_class <- function(plot){
plot$layout <- ggproto("SubClassLayout", plot$layout, ...)
NextMethod()
} I could see this working. I think this would be more reliable than I do wonder what effect this may have on packages that already have their own |
I'm sure we can make a backward compatible change that will keep the packages running even if they haven't updated their build methods, though they might have some compatibility issues with extension packages that do implement their own layouts. I think keeping the create_layout <- function(facet, coord, layout = NULL) {
ggproto(NULL, layout %||% Layout, facet = facet, coord = coord)
} Then the rest of what you layed out seems to pan out as it should. I did a quick search and it seems that there are ~5-ish packages that have redefined the |
Shall I close this PR and open a new one? or just make the commits here? |
Whatever is most convenient to you, sometimes a fix requires some iteration to get it right :) |
…ough `plot$layout` is actually a Layout ggproto object
New updates:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the one suggestion I think this makes more sense now. I'd still would want @thomasp85's eyes on this as well, just to make sure I'm not out of my depth here. Have you also checked that this PR is sufficient for your purposes?
teunbrand's suggestion for checking Layout type Co-authored-by: Teun van den Brand <49372158+teunbrand@users.noreply.github.com>
This PR should be sufficient for my purposes with |
@thomasp85 A brief summary of this PR is that we allow extensions to implement a custom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@jtlandis Can I ask you to add a news bullet and rename this PR to something that reflects the contents more closely? |
…o modify the it would affect all future ggplot objects and any still in memory.
@teunbrand With your approval, I also made an edit to the ggplot object in which we wrap Layout in a ggproto call. The motivation to this is to keep the base |
Yes, good call. In theory anyone can mess around with the exported ggproto classes, including |
create_layout
as an s3 genericLayout
slot to ggplot object
This comment was marked as resolved.
This comment was marked as resolved.
Thanks you for the contribution! |
Creates a pull request for issue #5077
cleaner pull request for #5575