Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to fix #426.
Briefly, it introduces two classes of palettes:
<pal_continuous>
and<pal_discrete>
, which I mostly see as making {scales}' palettes more formal.The classes are simply functions with attributes that provide information about the palette.
The
<pal_discrete>
class accepts a scalarn
as input and spits out a vector ofn
distinct values.The
<pal_continuous>
class accepts a numeric vector between (0, 1) and spits out a vector of equal length.All existing palettes have been given appropriate classes.
The
palette_type()
function probes thetype
attribute, indicating what palettes can be used for, like"colour"
or"linetype"
.The
palette_na_safe()
function probes<pal_continuous>
on whetherNA
are translated (e.g. in using thecolour_ramp(na.colour)
argument).The
palette_nlevels()
function probes<pal_discrete>
what the maximumn
is.The
as_continuous_pal()
function can cast<pal_discrete>
to<pal_continuous>
. For colour types, this is wrapping the discrete palette incolour_ramp()
.The
as_discrete_pal()
function can cast<pal_continuous>
to<pal_discrete>
. This is mostlypalette_fun(seq(0, 1, length.out = n)
.A small demo:
Created on 2024-04-16 with reprex v2.1.0