Skip to content

Named palettes - #448

Merged
thomasp85 merged 15 commits into
r-lib:mainfrom
teunbrand:named_palettes
Oct 21, 2024
Merged

thomasp85 merged 15 commits into
r-lib:mainfrom
teunbrand:named_palettes

Conversation

@teunbrand

Copy link
Copy Markdown
Collaborator

This PR aims to fix #396.

Briefly, it adds a register of known palettes.

In some more detail, you can get one of the known palettes with get_palette(), set a new known palette with set_pallette(), see all known palettes with palette_names() and restore the default palettes with reset_palettes(). Along with these functions, there is integration with as_continuous/discrete_pal() and show_col() to work with known palettes.

The nice thing about having known palettes, is that you can refer to them by name.

devtools::load_all("~/packages/scales/")
#> ℹ Loading scales
show_col("Okabe-Ito")

This PR would nicely integrate with tidyverse/ggplot2#6112, as it would use as_continuous/discrete_pal() in the default colour scales.

pal <- as_discrete_pal("magma")
show_col(pal(16))

Palette packages are then able to register their own palettes, which you could then also refer to by name.

cols <- c("palegreen", "deepskyblue", "magenta")
set_palette("aurora", palette = cols)
show_col(as_continuous_pal("aurora"), labels = FALSE)

Created on 2024-09-19 with reprex v2.1.1

@thomasp85
thomasp85 self-requested a review September 24, 2024 08:53
@teunbrand

teunbrand commented Sep 25, 2024 •

Copy link
Copy Markdown
Collaborator Author

Some discussion in the issue around what the getters/setters should be called: #396 (comment).

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - thanks

@thomasp85

Copy link
Copy Markdown
Member

/document

@thomasp85
thomasp85 merged commit 88c4beb into r-lib:main Oct 21, 2024
@teunbrand
teunbrand deleted the named_palettes branch October 21, 2024 12:14
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.

Feature request: palette registration

2 participants