Title: | Assigns Colours to Values |
---|---|
Description: | Maps one of the viridis colour palettes, or a user-specified palette to values. Viridis colour maps are created by Stéfan van der Walt and Nathaniel Smith, and were set as the default palette for the 'Python' 'Matplotlib' library <https://matplotlib.org/>. Other palettes available in this library have been derived from 'RColorBrewer' <https://CRAN.R-project.org/package=RColorBrewer> and 'colorspace' <https://CRAN.R-project.org/package=colorspace> packages. |
Authors: | David Cooley [aut, cre] |
Maintainer: | David Cooley <[email protected]> |
License: | GPL-3 |
Version: | 0.3.10 |
Built: | 2024-11-11 05:00:17 UTC |
Source: | https://github.com/symbolixau/colourvalues |
List the available colour palettes.
colour_palettes(colours = NULL) color_palettes(colours = NULL)
colour_palettes(colours = NULL) color_palettes(colours = NULL)
colours |
vector of source colour palettes to return, one or many of "viridis","rcolorbrewer","grdevices","colorspace","colorramp". NULL will reutrn all palettes. |
The palettes avaialble in colourvalues
have been derived from those avaialble in
the libraries
viridis
RColorBrewer
grDevices
colorspaces
colorRamp
colour_palettes() colour_palettes( "viridis" ) colour_palettes( colours = c("rcolorbrewer","grdevices") )
colour_palettes() colour_palettes( "viridis" ) colour_palettes( colours = c("rcolorbrewer","grdevices") )
maps colours to values, returning a vector of hex strings
colour_values( x, palette = "viridis", alpha = 255, na_colour = "#808080FF", include_alpha = TRUE, summary = FALSE, n_summaries = 0, format = TRUE, digits = 2 ) color_values( x, palette = "viridis", alpha = 255, na_colour = "#808080FF", include_alpha = TRUE, summary = FALSE, n_summaries = 0, format = TRUE, digits = 2 ) ## S3 method for class 'character' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'logical' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'factor' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'Date' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'POSIXct' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'POSIXlt' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits )
colour_values( x, palette = "viridis", alpha = 255, na_colour = "#808080FF", include_alpha = TRUE, summary = FALSE, n_summaries = 0, format = TRUE, digits = 2 ) color_values( x, palette = "viridis", alpha = 255, na_colour = "#808080FF", include_alpha = TRUE, summary = FALSE, n_summaries = 0, format = TRUE, digits = 2 ) ## S3 method for class 'character' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'logical' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'factor' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'Date' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'POSIXct' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'POSIXlt' colour_values_to_hex( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits )
x |
vector of values to map to a colour |
palette |
colour palette. See details and examples |
alpha |
optional. Single value in [0,255] applied to all colours,
or a decimal in [0, 1) (to indicate a percentage, noting 1 is excluded),
or a vector of numeric values the same length as |
na_colour |
hex string colour to use for NA values in the form |
include_alpha |
logical indicating if the returned hex or matrix should include
the alpha values. Defaults to |
summary |
logical indicating if a summary of the colours should be returned as
well as the full colour mapping. This will be the unique elements of |
n_summaries |
positive integer. If supplied a summary colour palette will be returned
in a list, containing |
format |
logical indicating if the summary values should be formatted. |
digits |
number of decimal places to show in the summary |
The palette can either be
String - use colour_palettes()
to view available palettes
Matrix - At least 5 rows, and 3 (or 4) columns representing the red, green and blue (and alpha) values
The matrix palette
requires 5 rows because the colours are interpolated using a
cubic b-spline. This method requires 5 values.
colour_values_rgb
## in-built palettes colour_values(x = 1:5) ## default is "viridis" colour_values(x = 1:5, palette = "inferno") colour_values(x = 1:5, palette = "plasma") colour_values(x = 1:5, palette = "magma") colour_values(x = 1:5, palette = "cividis") colour_values(x = 1:5, palette = "rainbow") ## matrix palette n <- 100 m <- grDevices::colorRamp(c("red", "green"))( (1:n)/n ) df <- data.frame(a = 10, x = 1:n) df$col <- colour_values(df$x, palette = m) barplot(height = df$a, col = df$col, border = NA, space = 0) ## with an alpha column on the palette n <- 100 m <- grDevices::colorRamp(c("red", "green"))( (1:n)/n ) m <- cbind(m, seq(0, 255, length.out = 100)) df <- data.frame(a = 10, x = 1:n) df$col <- colour_values(df$x, palette = m) barplot(height = df$a, col = df$col, border = NA, space = 0) ## single alpha value for all colours df <- data.frame(a = 10, x = 1:255) df$col <- colour_values(df$x, alpha = 50) barplot(height = df$a, col = df$col, border = NA, space = 0) ## vector of alpha values df <- data.frame(a = 10, x = 1:300, y = rep(c(1:50, 50:1), 3) ) df$col <- colour_values(df$x, alpha = df$y) barplot(height = df$a, col = df$col, border = NA, space = 0) ## returning a summary palette colour_values(-10:10, n_summaries = 5) colour_values(x = runif(20, 0, 1), n_summaries = 3, digits = 2) colour_values(x = runif(20, 0, 1), n_summaries = 3, digits = 10) ## Formatting output ## default is TRUE colour_values( x = seq(as.Date("2023-01-01"), as.Date("2023-01-31"), by = 1) , n_summaries = 5 ) colour_values( x = seq(as.Date("2023-01-01"), as.Date("2023-01-31"), by = 1) , n_summaries = 5 , format = FALSE )
## in-built palettes colour_values(x = 1:5) ## default is "viridis" colour_values(x = 1:5, palette = "inferno") colour_values(x = 1:5, palette = "plasma") colour_values(x = 1:5, palette = "magma") colour_values(x = 1:5, palette = "cividis") colour_values(x = 1:5, palette = "rainbow") ## matrix palette n <- 100 m <- grDevices::colorRamp(c("red", "green"))( (1:n)/n ) df <- data.frame(a = 10, x = 1:n) df$col <- colour_values(df$x, palette = m) barplot(height = df$a, col = df$col, border = NA, space = 0) ## with an alpha column on the palette n <- 100 m <- grDevices::colorRamp(c("red", "green"))( (1:n)/n ) m <- cbind(m, seq(0, 255, length.out = 100)) df <- data.frame(a = 10, x = 1:n) df$col <- colour_values(df$x, palette = m) barplot(height = df$a, col = df$col, border = NA, space = 0) ## single alpha value for all colours df <- data.frame(a = 10, x = 1:255) df$col <- colour_values(df$x, alpha = 50) barplot(height = df$a, col = df$col, border = NA, space = 0) ## vector of alpha values df <- data.frame(a = 10, x = 1:300, y = rep(c(1:50, 50:1), 3) ) df$col <- colour_values(df$x, alpha = df$y) barplot(height = df$a, col = df$col, border = NA, space = 0) ## returning a summary palette colour_values(-10:10, n_summaries = 5) colour_values(x = runif(20, 0, 1), n_summaries = 3, digits = 2) colour_values(x = runif(20, 0, 1), n_summaries = 3, digits = 10) ## Formatting output ## default is TRUE colour_values( x = seq(as.Date("2023-01-01"), as.Date("2023-01-31"), by = 1) , n_summaries = 5 ) colour_values( x = seq(as.Date("2023-01-01"), as.Date("2023-01-31"), by = 1) , n_summaries = 5 , format = FALSE )
Maps colours to values, returning a matrix of RGB(A) values
colour_values_rgb( x, palette = "viridis", alpha = 255, na_colour = "#808080FF", include_alpha = TRUE, summary = FALSE, n_summaries = 0, format = TRUE, digits = 2 ) color_values_rgb( x, palette = "viridis", alpha = 255, na_colour = "#808080FF", include_alpha = TRUE, summary = FALSE, n_summaries = 0, format = TRUE, digits = 2 ) ## S3 method for class 'character' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'logical' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'factor' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'Date' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'POSIXct' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'POSIXlt' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits )
colour_values_rgb( x, palette = "viridis", alpha = 255, na_colour = "#808080FF", include_alpha = TRUE, summary = FALSE, n_summaries = 0, format = TRUE, digits = 2 ) color_values_rgb( x, palette = "viridis", alpha = 255, na_colour = "#808080FF", include_alpha = TRUE, summary = FALSE, n_summaries = 0, format = TRUE, digits = 2 ) ## S3 method for class 'character' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'logical' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'factor' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'Date' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'POSIXct' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits ) ## S3 method for class 'POSIXlt' colour_values_to_rgb( x, palette, alpha, na_colour, include_alpha, summary, n_summaries, format, digits )
x |
vector of values to map to a colour |
palette |
colour palette. See details and examples |
alpha |
optional. Single value in [0,255] applied to all colours,
or a decimal in [0, 1) (to indicate a percentage, noting 1 is excluded),
or a vector of numeric values the same length as |
na_colour |
hex string colour to use for NA values in the form |
include_alpha |
logical indicating if the returned hex or matrix should include
the alpha values. Defaults to |
summary |
logical indicating if a summary of the colours should be returned as
well as the full colour mapping. This will be the unique elements of |
n_summaries |
positive integer. If supplied a summary colour palette will be returned
in a list, containing |
format |
logical indicating if the summary values should be formatted. |
digits |
number of decimal places to show in the summary |
The palette can either be
String - use colour_palettes()
to view available palettes
Matrix - At least 5 rows, and 3 (or 4) columns representing the red, green and blue (and alpha) values
The matrix palette
requires 5 rows because the colours are interpolated using a
cubic b-spline. This method requires 5 values.
colour_values
colour_values_rgb(1:5) colour_values_rgb(1:5, include_alpha = FALSE) colour_values_rgb(-25:25, n_summaries = 5)
colour_values_rgb(1:5) colour_values_rgb(1:5, include_alpha = FALSE) colour_values_rgb(-25:25, n_summaries = 5)
Converts colours between RRGGBBAA and hex strings, in both directions.
convert_colour(x) convert_colours(x) convert_color(x) convert_colors(x)
convert_colour(x) convert_colours(x) convert_color(x) convert_colors(x)
x |
character vector of hex strings, or numeric matrix of RRGGBBAA values |
If a combination of hex strings with and without alpha values are supplied, those
without are assumed to have an alpha value of FF
and will be returned in the
RRGGBBAA matrix
convert_colour(c("#FFAA00")) convert_colour(c("#FFAA00","#FF00AAFF")) convert_colour(matrix(c(255,170,0),ncol = 3)) convert_colour(matrix(c(255,170,0,255),ncol = 4))
convert_colour(c("#FFAA00")) convert_colour(c("#FFAA00","#FF00AAFF")) convert_colour(matrix(c(255,170,0),ncol = 3)) convert_colour(matrix(c(255,170,0,255),ncol = 4))
retrieves one of the available palettes
get_palette(palette, rgb = TRUE)
get_palette(palette, rgb = TRUE)
palette |
one of the available paletes. See colour_palettes |
rgb |
logical indicating if the palette should be returned as an RGB matrix
|
3 column matrix if rgb = TRUE
, otherwise a 256-length vector.
get_palette( "viridis" ) get_palette( "rainbow" )
get_palette( "viridis" ) get_palette( "rainbow" )
Data Frame of the magenta2green palette
magenta2green()
magenta2green()
Data Frame of the sequential_hcl palette
sequential_hcl()
sequential_hcl()
Plots all the selected colours. See colour_palettes for avaialble colours.
show_colours(colours = colour_palettes())
show_colours(colours = colour_palettes())
colours |
vector of colour palettes |
## view all the colour palettes show_colours() ## view a selection of colour palettes show_colours( colours = colour_palettes( c("viridis", "grdevices") ) )
## view all the colour palettes show_colours() ## view a selection of colour palettes show_colours( colours = colour_palettes( c("viridis", "grdevices") ) )