Skip to content

feat: Support palette argument and palette.<aes>.* theme elements in pattern scales - #178

Merged
trevorld merged 1 commit into
masterfrom
palette-theme-172
Nov 22, 2026
Merged

trevorld merged 1 commit into
masterfrom
palette-theme-172

Conversation

@trevorld

Copy link
Copy Markdown
Owner

Closes #172.

Summary

  • Our scale_pattern_*_discrete() and scale_pattern_*_continuous() scales (and the ordinal scales, scale_pattern_linetype(), and scale_pattern_shape()) have a new palette argument. It takes precedence over choices or range.
  • Like {ggplot2}'s own scales, a scale created without a palette now looks one up in the palette.<aesthetic>.discrete or palette.<aesthetic>.continuous theme element, e.g. theme(palette.pattern_type.discrete = c("hexagonal", "rhombille", "pythagorean")). These theme elements are registered for every pattern aesthetic with a scale when {ggpattern} is loaded. The new ?pattern_palettes help page documents them.
  • choices, range, and solid now default to NULL so that the theme element can be used. The default palettes are unchanged.
  • A scale with no default palette, e.g. scale_pattern_type_discrete(), now errors when it is used without a palette instead of when it is made.
  • A palette argument or theme element that {scales} can't convert into a palette, such as a numeric vector, now errors with a hint: use scales::pal_manual(), the choices / range argument, or the manual scale.
  • scale_pattern_{colour,fill,fill2}_discrete() are no longer aliases of the _hue() scales, though they still accept their arguments.
  • The continuous colour scales' colourbar now takes its available_aes from aesthetics, so aesthetics = "pattern_color" keeps its legend.

The colour aesthetics have their own theme elements (palette.pattern_fill.discrete etc.) rather than reusing palette.fill.*. Otherwise mapping fill and pattern_fill to the same variable would draw patterns the same colour as their background.

Follow-ups split out: #175 (ordered pattern_shape scales), #176 (uneven continuous choices bins), #177 (no scales or theme palettes for pattern_option_*).

Testing

  • New tests for every scale's palette argument and theme element, and for the theme-element registration and class checks.
  • R CMD check: 0 errors, 0 warnings, 0 notes.

🤖 Generated with Claude Code

… in pattern scales (#172)

* Our `scale_pattern_*_discrete()` and `scale_pattern_*_continuous()` scales
  (and the ordinal, `scale_pattern_linetype()`, and `scale_pattern_shape()` scales)
  have a new `palette` argument which takes precedence over `choices` or `range`.
* Like `{ggplot2}`'s own scales they now look up their palette in the
  `palette.<aesthetic>.discrete` or `palette.<aesthetic>.continuous` theme element when not given one.
  We register these theme elements for every pattern aesthetic with a scale when `{ggpattern}` is loaded
  and document them in the new `?pattern_palettes`.
* The `choices`, `range`, and `solid` arguments now default to `NULL` so that the theme element can be used
  (the default palettes are unchanged).
  A scale without a default palette (e.g. `scale_pattern_type_discrete()`) now throws an error
  when it is used without one instead of when it is made.
* A `palette` (or theme element) that is a vector `{scales}` can't convert into a palette
  is an error suggesting `scales::pal_manual()`, the `choices` or `range` argument, or the manual scale.
* `scale_pattern_colour_discrete()`, `scale_pattern_fill_discrete()`, and `scale_pattern_fill2_discrete()`
  are no longer aliases of the `scale_pattern_*_hue()` scales and the continuous colour scales'
  colourbar now takes its `available_aes` from `aesthetics`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trevorld
trevorld merged commit 5641218 into master Nov 22, 2026
3 checks passed
@trevorld
trevorld deleted the palette-theme-172 branch November 22, 2026 22:38
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.

Support palette argument and palette.<aes>.* theme elements in pattern scales

1 participant