Skip to content

fix: Continuous choices scales split the data into equal-width bins (#176) - #179

Merged
trevorld merged 2 commits into
masterfrom
fix-continuous-choices
Nov 23, 2026
Merged

trevorld merged 2 commits into
masterfrom
fix-continuous-choices

Conversation

@trevorld

Copy link
Copy Markdown
Owner

Closes #176.

  • pal_choices_continuous() (used by scale_pattern_continuous() and the scale_pattern_*_continuous() scales that pick from choices) now splits [0, 1] into length(choices) equal-width bins instead of only using the last choice at the maximum.
    For 1:10 with three choices this gives 4, 3, and 3 values (previously 5, 4, and 1).
  • Bins are closed on the right like {ggplot2}'s binned scales and our pal_choices_discrete(), so evenly spaced values get the same choices as the discrete scale gives them as a factor.
    This differs from the 3, 3, 4 split proposed in Continuous choices scales give the last choice only at the maximum #176.
  • A value within sqrt(.Machine$double.eps) of a bin width of an edge counts as on it (like the fuzz of hist()).
    Plain ceiling(x * n) misbinned 287 of 3894 evenly spaced test cases because of rounding error (e.g. a rescaled 0.6 times 5 is 3.0000000000000004), and cut() with seq() breaks misbinned 415.
  • Values outside [0, 1] (e.g. with oob = scales::oob_keep) are now NA on both sides like in {ggplot2}'s binned scales (previously NA above and choices[0] or negative indices below).
  • The choices docs now describe how continuous scales bin values, and NEWS lists this under breaking changes since some values now get a different choice.

A second commit syncs vignettes/patterns-image.Rmd.orig with the defaults tables 321e8b3 made only to the knitted .Rmd, and adds the "Removed 7 rows" warning (which ggplot2::geom_bin2d() gives too) to the bin2d gallery examples.
The precomputed vignette images are deliberately not updated yet (to be regenerated before the CRAN release).

🤖 Generated with Claude Code

trevorld and others added 2 commits November 23, 2026 09:58
…#176)

* `scale_pattern_continuous()` and the `scale_pattern_*_continuous()` scales that pick from `choices`
  previously only used the last choice at the maximum
  (`pal_choices_continuous()` truncated over `length(choices) - 1` steps).
* `pal_choices_continuous()` now splits [0, 1] into `length(choices)` equal-width bins
  closed on the right like `{ggplot2}`'s binned scales and `pal_choices_discrete()`
  (so evenly spaced values get the same choices as the discrete scale gives them as a factor).
  A value within `sqrt(.Machine$double.eps)` of a bin width of an edge counts as on it
  (like the `fuzz` of `hist()`) so that edges aren't missed because of rounding error.
* Values outside [0, 1] (e.g. with `oob = scales::oob_keep`) are now `NA` like in `{ggplot2}`'s binned scales.
* The `choices` documentation now describes how continuous scales bin values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mage.Rmd.orig`

* `patterns-image.Rmd.orig` now has the updated aesthetic defaults tables
  that 321e8b3 only made to the knitted `patterns-image.Rmd`
  (so precomputing the vignette no longer reverts them).
* The `geom_bin2d_pattern()` gallery examples now show the
  "Removed 7 rows containing missing values" warning
  that `GeomTilePattern` now gives like `ggplot2::geom_bin2d()`.
* The precomputed images aren't updated yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trevorld
trevorld merged commit 1939f61 into master Nov 23, 2026
3 checks passed
@trevorld
trevorld deleted the fix-continuous-choices branch November 23, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Continuous choices scales give the last choice only at the maximum

1 participant