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

create_layout as a S3 generic #5077

Closed
jtlandis opened this issue Dec 2, 2022 · 3 comments
Closed

create_layout as a S3 generic #5077

jtlandis opened this issue Dec 2, 2022 · 3 comments
Labels
feature a feature request or enhancement internals 🔎

Comments

@jtlandis
Copy link
Contributor

jtlandis commented Dec 2, 2022

I am curious if the developers of ggplot2 would be open to making a create_layout S3 generic, that takes one parameter plot.

It may look something like the following

create_layout <- function(plot) UseMethod("create_layout", plot)
create_layout.ggplot <- function(plot) {
    ggproto(NULL, Layout, facet = plot$facet, plot$coordinates)
}

The main motivation is to allow for users to rely on ggplot2's own plot_build method without having to rewrite the entire method just to change the Layout's functionality slightly. I see this was briefly up for debate before. As a result of #2527, only the Layer ggproto class was exported, but create_layout was not.

A specific use case I would like to build is to create a Layout that does not assume all panels have the same scales type. Many places in the code, ggplot2 assumes all y positional scales share the same aesthetics so you see the following self$panel_scales_y[[1]]$aesthetics whereas my implementation may look something like unique(unlist(lapply(self$panel_scales_y, function(s) s$aesthetics)))

@teunbrand teunbrand added feature a feature request or enhancement internals 🔎 labels Jan 7, 2023
@jtlandis
Copy link
Contributor Author

Would the developers consider adding this in the next release of ggplot2?

It feels like a minor change to implement.

@teunbrand
Copy link
Collaborator

I'm not opposed to this. Do you feel like setting up a PR?

@teunbrand
Copy link
Collaborator

teunbrand commented Dec 15, 2023

I consider this issue fixed by #5576.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement internals 🔎
Projects
None yet
Development

No branches or pull requests

2 participants