Set common scale parameters outside of the scale function

Open
#4,269 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
r

Research direction

Start by reading R/limits.r, R/labels.r, R/plot-build.r, and R/layout.R, then reproduce the two examples in the issue to understand their differing scale behavior. The issue does not define a concrete API or implementation target, so completion would require agreeing on a generic approach and its expected behavior for limits, labels, expansions, breaks, and discrete scales.

Written by the indexing model from the issue text.

Description

feature scales :snake:

A problem that pops up repeatedly in different contexts is that we may want to adjust certain scale parameters without explicitly calling a scale function. We already have some support for this, e.g. with xlim() to set limits on the x position scale or xlab() to set its title, but there are numerous other scenarios where the same problem arises. Here are some examples:

It would be good if we could come up with a generic approach to these issues. I note that xlim() and xlab() use entirely different implementation approaches currently, so that's not promising:

Neither approach generalizes directly to the other use cases. I also have concerns about the way xlim() and ylim() are implemented, because the fact that they add explicit scales functions is not obvious and can lead to strange behavior. See e.g. the following reprex, where in the first plot the call to scale_x_continuous() overwrites the xlim() call but in the second plot the xlab() call is not overwritten:

library(ggplot2)

ggplot(mtcars, aes(disp, mpg)) +
  geom_point() +
  xlim(100, 300) +
  scale_x_continuous(name = "Displacement")
#> Scale for 'x' is already present. Adding another scale for 'x', which will
#> replace the existing scale.

ggplot(mtcars, aes(disp, mpg)) +
  geom_point() +
  xlab("Displacement") +
  scale_x_continuous(limits = c(100, 300))
#> Warning: Removed 16 rows containing missing values (geom_point).

Created on 2020-11-17 by the reprex package (v0.3.0)

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

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.

More from tidyverse/ggplot2

All issues in tidyverse/ggplot2

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.