Skip to content

Export default_expansion() and expand_limits_scale() for coord extensions #6888

Description

@matthewkling

I'd like to request that default_expansion() and expand_limits_scale() be exported (or that equivalent public functions be provided). These two internal helpers appear to be the only way for a coord extension to reproduce ggplot2's exact axis-expansion behavior.

I maintain ggcube, a coord extension that adds a 3D coordinate system (coord_3d()) to ggplot2. Because it extends CoordCartesian, it needs to expand scale limits identically to core ggplot2 — including taking a user-supplied expand argument — so that the z axis behaves like the x and y axes. To do this, the relevant ggcube code currently uses these internal functions by reaching into the ggplot2 namespace:

default_expansion   <- utils::getFromNamespace("default_expansion",   "ggplot2")
expand_limits_scale <- utils::getFromNamespace("expand_limits_scale", "ggplot2")

expansion      <- default_expansion(scale, expand = expand)
expanded_range <- expand_limits_scale(scale, expansion, limits, coord_limits = NULL)

Relying on these internals is fragile. If they were exported, it would fix that risk. ggplot2 already exports some adjacent helper functions, including expansion() and expand_limits(), so there seems to be a precedent.

Thanks for considering.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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