Format or create colors for a vector with categorical values
format_colors_cat.Rd
Make sure that unique named colors are created for each value.
Usage
format_colors_cat(
x,
colors = NULL,
palette = NULL,
rev = FALSE,
allow_duplicated = TRUE
)
format_colors(
x,
colors = NULL,
palette = NULL,
rev = FALSE,
allow_duplicated = TRUE
)
format_colors_cat_strata(x, strata = NULL, palette = NULL, rev = FALSE)
Arguments
- x
Vector of categorical values for which we want to specify colors.
- colors
Vector of colors longer or equal the number of unique levels of x. Can be named or non-named. If NULL, colors are generated.
- palette
List of length corresponding the number of levels in strata with colors or names of RColorBrewer palettes. E.g. `list("Blues", "Oranges", "Greens", "Purples", "Reds", "Greys")`
- strata
Vector of categorical values of stratification groups.
Examples
x <- c("low", "high")
colors <- c("high" = "red", "low" = "grey")
palette <- NULL
allow_duplicated <- FALSE
format_colors_cat(x, colors = colors, palette = palette, allow_duplicated = allow_duplicated)
#> low high
#> "grey" "red"
x <- c("<1", "<2", "<3", "<4")
colors <- NULL
palette <- "RdYlBu"
allow_duplicated <- FALSE
out <- format_colors_cat(x, colors = colors, palette = palette, allow_duplicated = allow_duplicated)
barplot(rep(1, length(out)), col = out)