Skip to content

create_layout as a S3 generic #5077

Closed
Closed
@jtlandis

Description

@jtlandis

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)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions