Learn R Programming

factoextra (version 2.2.0)

factoextra_palette: Colorblind-safe color palette for factoextra plots

Description

Returns a colorblind-safe categorical color palette as a character vector of hex codes, to pass explicitly to the palette argument of the fviz_*() functions (e.g. fviz_cluster(res, palette = factoextra_palette("okabe"))). The default is the Okabe-Ito color-universal-design palette, which stays distinguishable under the common forms of color-vision deficiency.

The palette is returned as a plain color vector (not a ggplot2 scale), for the existing palette argument. Use it for discrete group coloring (habillage, a factor col.ind, or clusters), where it also tints the matching ellipse fills. For a continuous metric (e.g. col.ind = "cos2") use gradient.cols instead — a categorical palette does not apply there. It introduces no global option and no hidden state. The colors are ordered so the highest-contrast hues come first; yellow, the palest on a white background, is placed late, so plots with a few groups stay crisp.

Read more: ggplot2 Colours in R: Change Colours by Group.

Usage

factoextra_palette(palette = "okabe", n = NULL)

Value

A character vector of hex color codes.

Arguments

palette

name of the palette. Currently "okabe" (alias "okabe-ito"), the Okabe-Ito color-universal-design set.

n

number of colors to return. NULL (default) returns the whole palette. If n is greater than the number of available colors the palette is recycled (with a message), since recycling defeats the distinguishability the palette is chosen for.

Details

The Okabe-Ito colors are those of grDevices::palette.colors( palette = "Okabe-Ito") (here reordered so the vivid hues lead, with grey and black last). They were designed by Masataka Okabe and Kei Ito as a color-universal-design set, and popularized for figures by Wong (2011).

References

Okabe, M. and Ito, K. (2008). Color Universal Design (CUD): How to make figures and presentations that are friendly to colorblind people. https://jfly.uni-koeln.de/color/.

Wong, B. (2011). Points of view: Color blindness. Nature Methods, 8(6), 441. tools:::Rd_expr_doi("10.1038/nmeth.1618").

See Also

theme_factoextra. Online tutorial: ggplot2 Colours in R: Change Colours by Group.

Examples

Run this code
# A colorblind-safe categorical palette
factoextra_palette("okabe")
factoextra_palette("okabe", n = 3)

# \donttest{
# Publication-grade recipe: colorblind-safe groups + a clean theme
data(iris)
km <- kmeans(scale(iris[, 1:4]), 3, nstart = 25)
fviz_cluster(km, data = iris[, 1:4],
             palette = factoextra_palette("okabe"),
             ggtheme = theme_factoextra())
# }

Run the code above in your browser using DataLab