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.
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. Ifnis 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. doi:10.1038/nmeth.1618 .
See also
theme_factoextra.
Online tutorial: ggplot2 Colours in R: Change Colours by Group.
Examples
# A colorblind-safe categorical palette
factoextra_palette("okabe")
#> [1] "#E69F00" "#56B4E9" "#009E73" "#D55E00" "#0072B2" "#CC79A7" "#F0E442"
#> [8] "#999999" "#000000"
factoextra_palette("okabe", n = 3)
#> [1] "#E69F00" "#56B4E9" "#009E73"
# \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())
# }
