Skip to content

Feature request: Add gg class in ggplot2::labs() #5553

@Yunuuuu

Description

@Yunuuuu

If both functions perform the same tasks for ggplot2 elements, we can use a single function like ggbuild_fn to re-dispatch methods. However, the issue arises when the value of ggplot2::labs() does not have a gg class.

# If both function do same things for ggplot2 elements
# we can re-dispatch methods with a single function like `ggbuild_fn`
first_fn <- function(x) {
    UseMethod("first_fn")
}
first_fn.gg <- function(x) {
    ggbuild_fn(x)
}
second_fn <- function(x) {
    UseMethod("second_fn")
}
second_fn.gg <- function(x) {
    ggbuild_fn(x)
}
# re-dispatch methods for exact ggplot2 elements
ggbuild_fn <- function(x) {
    UseMethod("ggbuild_fn")
}
ggbuild_fn.theme <- function(x) {
    # do something ...
}

ggbuild_fn.Scale <- function(x) {
    # do something ...
}

ggbuild_fn.labels <- function(x) {
    # do something ...
}

ggbuild_fn.Layer <- function(x) {
    # do something ...
}
class(ggplot2::scale_alpha_binned())
#> [1] "ScaleBinned" "Scale"       "ggproto"     "gg"
class(ggplot2::geom_point())
#> [1] "LayerInstance" "Layer"         "ggproto"       "gg"
class(ggplot2::theme())
#> [1] "theme" "gg"
class(ggplot2::labs())
#> [1] "labels"

Created on 2023-12-01 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions