View source: R/theme_palette.R
| factoextra_palette | R Documentation |
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.
factoextra_palette(palette = "okabe", n = NULL)
palette |
name of the palette. Currently |
n |
number of colors to return. |
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).
A character vector of hex color codes.
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. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1038/nmeth.1618")}.
theme_factoextra.
Online tutorial: ggplot2 Colours in R: Change Colours by Group.
# A colorblind-safe categorical palette
factoextra_palette("okabe")
factoextra_palette("okabe", n = 3)
# 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())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.