It maps viridis colours (by default) to values, and quickly!
Note It does not perform a 1-to-1 mapping of a palette to values. It
interpolates the colours from a given palette.
Why did you build it?
I’m aware there are other methods for mapping colours to values. And
which do it quick too. But I can never remember them, and I find the
interfaces a bit cumbersome. For example,
scales::col_numeric(palette = viridisLite::viridis(5), domain = range(1:5))(1:5).
I wanted one function which will work on one argument.
colourvalues
What does it do?
It maps viridis colours (by default) to values, and quickly!
Note It does not perform a 1-to-1 mapping of a palette to values. It interpolates the colours from a given palette.
Why did you build it?
I’m aware there are other methods for mapping colours to values. And which do it quick too. But I can never remember them, and I find the interfaces a bit cumbersome. For example,
scales::col_numeric(palette = viridisLite::viridis(5), domain = range(1:5))(1:5).I wanted one function which will work on one argument.
I also want it available at the
src(C/C++) level for linking to other packages.Why do you spell colour with a ‘u’?
Because it’s correct, and R tells us to
But don’t worry,
color_values(1:5)works as wellHow do I install it?
From CRAN
Or install the development version from GitHub with:
How can I make use of it in my package?
Rcpp
All functions are written in
Rcpp. I have exposed some of them in header files so you can “link to” them in your package.For example, the
LinkingTosection inDESCRIPTIONwill look something likeAnd in a c++ source file so you can
#includethe API headerAnd call
R
If you’re not using
Rcpp, justImportthis package like you would any other.Do you have any examples?
Of course!
256 numbers mapped to a colour
5000 numbers on a non-linear scale
1000 random numbers
Eurgh!
That’s better!
Are there only viridis palettes?
No, you can chose one from
And you can use
show_colours()to view them all. Here’s what some of them look likeDo I have to use the in-built palettes?
No, you can use your own specified as a matrix of red, green and blue columns in the range [0,255]
Do you support ‘alpha’ values
Yep. Either supply a single alpha value for all the colours
Or use a vector of values the same length as
xOr include the alpha value as a 4th column in the palette matrix
Some of my plotting functions don’t support alpha, can I exclude it?
Yep. Set
include_alpha = FALSECan I get a summary of colours to use in a legend?
Yes, for numeric values use the
n_summariesargument to specify the number of summary values you’d likeYou can also specify the number of digits you’d like returned in the summary
You can also use
format = FALSEif you don’t want the summary values formatted.For categorical values use
summary = TRUEto return a uniqe set of the values, and their associated coloursI see you support lists, but how does it work?
Basically, it’s the same as un-listing the list to create a vector of all the values, then colouring them.
So if your list contains different types, it will coerce all values to the same type and colour them.
But it returns a list of the same structure.
For example,
What it doesn’t do is treat each list element independently. For this you would use
What’s the performance like?
10 million numeric values
1 million characters (26 unique values)