This function uses dynamic arguments (...) in order to combine multiple color palettes together.

combination_palette(...)

Arguments

...

You can use any name for your arguments, but the values must be a named list. The list can only have 4 named members:

palette

This is a palette function that returns a vector of colors.

args

This is another named list used for the palette function parameters.

range

This is a range (1:10) used to subset the color palette vector.

rev

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.

Value

The output of this function is another function (grDevoces::colorRampPalette), which takes a number to generate an interpolated color palette as a character vector.

Details

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.

See also

Examples

# NOT RUN {
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)
}
 }
# }