Skip to content

farmerClarkson/cols4all

 
 

Repository files navigation

Colors for all!

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

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 three types: categorical (qualitative) palettes, sequential palettes, and diverging palettes. In the near future, more palette types will be added, such as cyclic, bivariate, and hierarchical.

Installation

cols4all will be available on CRAN soon. Until then it can be installed using:

# install.packages("devtools")
devtools::install_github("mtennekes/cols4all")
#> [1] "/home/mtes/git/cols4all"
#> ℹ Loading cols4all
#> Loading required package: abind
#> Loading required package: colorspace

Getting started

Navigation through the color palettes is easy via the GUI shown above, which is started with:

library(cols4all)
# For the GUI, shiny, shinyjs, and kableExtra are required
# install.packages(c("shiny", "shinyjs", "kableExtra"))
c4a_gui()

Besides browsing through palettes, it is also easy to copy color codes to the clipboard, either by selecting the hidden text in the color tables or by clicking on the icons at the right-hand-side:

Selecting a palette is easy:

# Select the palette "kelly" with 7 colors
c4a("kelly", 7)
#> [1] "#F3C300" "#875692" "#F38400" "#A1CAF1" "#BE0032" "#C2B280" "#848482"

# 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] "#481F50" "#81488C" "#B473C1" "#D2A9DA" "#E7D3EC" "#F1F1F1" "#C7E0C9"
#>  [8] "#91C392" "#4D9D4E" "#256C26" "#013902"

# get the associated color for missing values
c4a_na("hcl.purple_green")
#> [1] "#868686"

Overview of functions

Main functions:

  • c4a_gui GUI (shiny app) to see and analyse the palettes
  • c4a Get the colors of a palette

Palette names and properties:

  • c4a_palettes Get available palette names
  • c4a_series Get available series
  • c4a_meta Get meta information (such as type and maximum number of colors )
  • c4a_ls Environment via which palette names can be browsed with auto-completion (using $)

Importing and exporting palettes:

  • c4a_series_add Add color palettes
  • c4a_series_remove Remove color palettes
  • c4a_sysdata_import Import system data
  • c4a_sysdata_export Export system data

ggplot2

  • scale_<aesthetic>_<mapping>_c4a_<type> e.g. scale_color_continuous_c4a_div Add scale to ggplot2.

Related R packages

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.

Feedback welcome!

  • 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)

About

Colors for all (R package)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • R 88.2%
  • Python 11.8%