choosePalette: Choose discrete colours

View source: R/func_basics.R

choosePaletteR Documentation

Choose discrete colours

Description

Given a character vector of features and optionally a vector of color codes, this function evaluate if the supplied color codes has sufficient number of colours. It returns a named vector of color codes based on the input features, with the same length as the unique features.

Usage

choosePalette(object, color = c30(), quiet = TRUE)

Arguments

object

A character vector containing the discrete or categorical features.

color

A character vector of color codes. Default is to use c30(), a palette with 30 colours.

quiet

Logical scalar indicating whether to disable messaging. Default is TRUE.

Details

By default, it uses the c30() palette when no more than 30 colours are required, then the c40() palette, and lastly the rainbow() colour palette when requiring more than 40 colours.

Value

A named character vector

Author(s)

I-Hsuan Lin

See Also

c30(), c40(), grDevices::rainbow()

Examples

# When input is a vector
feat <- LETTERS[1:5]
feat
choosePalette(feat) # use c30()

# When input is a factor of 3 levels
feat <- factor(rep(LETTERS[1:3], 5))
feat
choosePalette(feat, rainbow(10))

ycl6/scRUtils documentation built on Feb. 18, 2025, 6:14 a.m.