Learn R Programming

clinUtils (version 0.1.4)

getColorPalette: Get a color palette for clinical visualizations.

Description

Get a color palette of specified length, either from a vector of names for the palette, or from a specified length.

Usage

getColorPalette(n = NULL, x = NULL, includeNA = FALSE, palette = clinColors)

Value

Vector of colors, named with the elements in x if x is specified.

Arguments

n

Integer of length 1, number of elements in palette.

x

Vector with elements used for palette. If factor, the levels are used, otherwise the unique elements of the vector. Missing values are automatically removed, excepted if includeNA is set to TRUE.

includeNA

Logical (FALSE by default), should NA elements be retained in the palette in case x is specified?

palette

A vector of custom colors, or a function returning this vector from a specific number of colors.
Default is the the colorblind viridis color palette.

Author

Laure Cougnaud and Michela Pasetto

Examples

Run this code
# extract longest palette available
getColorPalette(n = 11)
# extract palette for a vector
getColorPalette(x = paste('treatment', 1:4))
# possibility to include missing values:
getColorPalette(x = c(NA_character_, "group1"), includeNA = FALSE)
getColorPalette(x = c(NA_character_, "group1"), includeNA = TRUE)
# change default settings
getColorPalette(n = 3, palette = c("red", "green", "grey"))

Run the code above in your browser using DataLab