This function uses dynamic arguments (...) in order to combine multiple color palettes together.
combination_palette(...)You can use any name for your arguments, but the values must be a named list. The list can only have 4 named members:
This is a palette function that returns a vector of colors.
This is another named list used for the palette function parameters.
This is a range (1:10) used to subset the color palette vector.
This is a logical (TRUE/FALSE) used to reverse the color palette.
You can add as many parameters you want in order to combine as many color palettes as you want.
The output of this function is another function (grDevoces::colorRampPalette), which takes a number to generate an interpolated color palette as a character vector.
This function allows you to combine a varying number of color palettes and gives you the ability to subset and reverse the palettes that are supplied.
Other Color Palettes:
get_color_palette(),
scico_palette(),
viridis_magma_palette(),
viridis_palette()
if (FALSE) { # \dontrun{
if(interactive()){
# Below is the code for the viridis_magma_palette function.
# It's a good example of how to use the combination_palette function.
viridis_magma_palette <- function(viridis_number = 800,
viridis_range = 300:viridis_number,
viridis_rev = TRUE,
magma_number = 500,
magma_range = 0:magma_number,
magma_rev = FALSE,
...) {
if (!missing(...)){
v_args = list(n=viridis_number, ...)
m_args = list(n=magma_number, ...)
} else {
v_args = list(n=viridis_number)
m_args = list(n=magma_number)
}
crp <- combination_palette(viridis =
list(palette = viridis::viridis,
args = v_args,
range = viridis_range,
rev = viridis_rev),
magma =
list(palette = viridis::magma,
args = m_args,
range = magma_range,
rev = magma_rev)
)
return(crp)
}
}
} # }