tidyverse / tidyverse/ggplot2

Export `default_expansion()` and `expand_limits_scale()` for coord extensions

Open
#6,888 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature scales :snake:
Dominant language
R
Stars
7k
Forks
2.1k
Avg merge
59m
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the internal default_expansion() and expand_limits_scale() helpers alongside the already exported expansion() and expand_limits() functions. Determine whether exporting the helpers or providing equivalent public functions best supports coord extensions such as ggcube, with user-supplied expansion and matching x/y axis behavior as the completion criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.