The cols4all is a new R package for selecting color palettes. “Color for all” refers to our mission that colors should be usable for not just people with normal color vision, but also for people with color vision deficiency. Currently, this package contains palettes from several popular and lesser known color palette series: Color Brewer, Viridis, Kovesi, Paul Tol, Scico, Carto, Tableau, Wes Anderson, and Seaborn. Own palettes series can be added as well.
Categorical | Sequential | Diverging |
---|---|---|
Bivariate (seq x seq) | Bivariate (seq x cat) | Bivariate (seq x desaturated) |
---|---|---|
Color palettes are well organized and made consistent with each other. Moreover, they are scored on several aspects: color-blind-friendliness, the presence of intense colors (which should be avoided), the overall aesthetic harmony, and how many different hues are used. Finally, for each color palette a color for missing values is assigned, which is especially important for spatial data visualization. Currently we support several types: categorical (qualitative) palettes, sequential palettes, diverging palettes, and bivariate palettes (divided into three subtypes).
cols4all will be available on CRAN soon. Until then it can be installed using:
# install.packages("devtools")
remotes::install_github("mtennekes/cols4all")
Navigation through the color palettes is easy via the GUI shown above, which is started with:
library(cols4all)
c4a_gui()
Selecting a palette is easy:
# Select the palette "kelly" with 7 colors
c4a("kelly", 7)
#> [1] "#F2F3F4" "#222222" "#F3C300" "#875692" "#F38400" "#A1CAF1" "#BE0032"
# find names of hcl palettes that are diverging
c4a_palettes(type = "div", series = "hcl")
#> [1] "hcl.blue_red1" "hcl.blue_red2" "hcl.blue_red3" "hcl.red_green"
#> [5] "hcl.purple_green" "hcl.purple_brown" "hcl.green_brown" "hcl.blue_yellow2"
#> [9] "hcl.blue_yellow3" "hcl.green_orange" "hcl.cyan_magenta"
# select purple green palette from the hcl series:
c4a("hcl.purple_green", 11)
#> [1] "#492050" "#82498C" "#B574C2" "#D2A9DB" "#E8D4ED" "#F1F1F1" "#C8E1C9"
#> [8] "#91C392" "#4E9D4F" "#256C26" "#023903"
# get the associated color for missing values
c4a_na("hcl.purple_green")
#> [1] "#868686"
Main functions:
c4a_gui
GUI (shiny app) to see and analyse the palettesc4a
Get the colors of a palette
Palette names and properties:
c4a_palettes
Get available palette namesc4a_series
Get available series namesc4a_info
Get palette information (such as type and maximum number of colors)c4a_citation
Show how to cite palettes (with bibtex code)..P
Environment via which palette names can be browsed with auto-completion (using$
)
Importing and exporting palettes:
c4a_palettes_add
Add color palettesc4a_palettes_remove
Remove color palettesc4a_sysdata_import
Import system datac4a_sysdata_export
Export system data
ggplot2
scale_<aesthetic>_<mapping>_c4a_<type>
e.g.scale_color_continuous_c4a_div
Add scale to ggplot2.
The foundation of this package is another R package: colorspace. We use this package to analyse colors. For this purpose and specifically for color blind friendliness checks, we also use colorblindcheck.
There are a few other pacakges with a large collection of color palettes, in particular pals and paletteer. There are a few features that distinguishes cols4all from those packages:
-
Colors for missing values are made explicit. For this, either a greyscale color that is already contained in the palette is used, or a greyscale color is selected that is distinguisable, also for people with color vision deficiency.
-
Palettes are made consistent with each other. For instance, sequential palettes (except for spectral/rainbow palettes) all start with the lightest color and end with the darkest color. Furthermore, black and white are removed from most categorical palettes for practical reasons: white or light grey is almost always used as background color and black for annotation.
-
The GUI enables users to analyse characteristics of color palettes, such as color-blind-friendliness, harmony, and the presence of intense colors.
-
There is native support for ggplot2 and tmap (as of the upcoming version 4).
-
It will be possible to submit an own series of color palettes.
-
Is everything working as expected?
-
Do you miss certain palettes or series?
-
Do you have ideas for improvement how to measure palette properties?
Let us know! (via github issues)