usecol allows using a color or color palette pal (e.g., for plotting). usecol also allows modifying and combining color palettes in various ways.

usecol(
  pal = unhcr_pal,
  n = "all",
  alpha = NA,
  use_names = FALSE,
  use_col_ramp = FALSE
)

Arguments

pal

A color palette (as a vector of colors or color palettes). Default: pal = unhcr_pal.

n

An integer value specifying the desired number of colors from the palette. Default: n = "all" (i.e., use all colors of a color palette). For the palettes defined by unhcr, n is set to a pre-defined selection of colors if the desired number of colors is smaller than the available number. For all other palettes and values of n larger than length(pal), n compresses or extends the palette using colorRampPalette.

alpha

A factor modifying the opacity alpha (as in adjustcolor); to a value in [0,1]. Default: alpha = NA (i.e., no modification of opacity).

use_names

A logical value indicating whether colors should be returned as a named vector. Default: use_names = FALSE, for compatibility with ggplot.

use_col_ramp

A logical value specifying whether the default of using pre-selected colors should be overridden and colorRampPalette should be used to process n. Default: use_col_ramp = FALSE.

Value

A vector of colors (in character format).

See also

seecol to plot color palettes; unhcr_pal for the default UNHCR color palette.

Examples

{ usecol(pal = unhcr_pal, n = "all") # default color palette usecol(pal = unhcr_pal, n = 4) # selecting n dedicated colors usecol(pal = unhcr_pal, n = 20) # extending color palette # Mixing a new color palette: pal_1 <- usecol(pal = c(rev(pal_blue), "white", pal_red)) seecol(pal_1) # Mixing and extending a color palette: pal_2 <- usecol(pal = c(rev(pal_green), "white", pal_red), n = 20) seecol(pal_2) }
#> Error in parse_pal(pal = pal): Input "pal" does not exist