knitr::opts_chunk$set( collapse = TRUE, fig.width=6, fig.height=3, comment = "#>" ) hook_output <- knitr::knit_hooks$get("output") knitr::knit_hooks$set(output = function(x, options) { lines <- options$output.lines if (is.null(lines)) { return(hook_output(x, options)) # pass to default hook } x <- unlist(strsplit(x, "\n")) more <- "..." if (length(lines)==1) { # first n lines if (length(x) > lines) { # truncate the output, but add .... x <- c(head(x, lines), more) } } else { x <- c(more, x[lines], more) } # paste these lines together x <- paste(c(x, ""), collapse = "\n") hook_output(x, options) })
library(cols4all)
The most extensive collection of color palettes in R is the package paletteer by Emil Hvitfeldt@paletteer. Let's load these palettes into \texttt{cols4all}.
The prepared system data can be loaded as follows:
paletteer = readRDS(gzcon(url("https://mtennekes.github.io/cols4all/paletteer.rds"))) # from paletteer version 1.6.0 c4a_sysdata_import(paletteer)
Note that this system data import will replace the default cols4all palettes. This is convenient because almost all cols4all palettes are also contained in paletteer. The only exceptions are the cols4all palette series "powerbi"
and "cols4all"
.
An overview of the number of available palettes:
(m <- c4a_overview(return.matrix = TRUE))
There are in total r sum(m)
palettes, and by palette type:
colSums(m)
Now we can start the interactive tool:
c4a_gui()
First we will see all categorical palettes of length 7, sorted by name. When we filter on color blind friendliness and sort by fairness we get this table:
#| fig.alt = "Fair categorical palettes of 7 colors, filtered by colorblind-friendliness", #| out.width = 800, #| echo = FALSE, knitr::include_graphics("../man/figures/paletteer_cbf.png")
As you can see, the top three palettes are identical, namely the palette by Okabe and Ito@okabe, but from difference R package sources and variations regarding the the eighth color (black or gray).
The other way round, when we filter on fair and sort by colorblind-friendliness we get this table:
#| fig.alt = "Fair categorical palettes of 7 colors, filtered by colorblind-friendliness", #| out.width = 800, #| echo = FALSE, knitr::include_graphics("../man/figures/paletteer_fair.png")
Observe that there are no color palettes of length 7 that are both color-blind friendly and fair. The good news is that cols4all contains a few new preliminary palettes that meet both criteria. See strategies for palette design.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.