Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named palettes #448

Merged
merged 15 commits into from
Oct 21, 2024
Merged

Named palettes #448

merged 15 commits into from
Oct 21, 2024

Conversation

teunbrand
Copy link
Contributor

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
Copy link
Contributor Author

teunbrand commented Sep 25, 2024

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

Copy link
Member

@thomasp85 thomasp85 left a comment

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
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