colorblindcheck: Check Color Palettes for Problems with Color Vision Deficiency

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Deciding if a color palette is a colorblind friendly is a hard task. This cannot be done in an entirely automatic fashion, as the decision needs to be confirmed by visual judgments. The goal of colorblindcheck is to provide tools to decide if the selected color palette is colorblind friendly, including:

The work in this package was inspired by a blog post I wrote some code that automatically checks visualizations for non-colorblind safe colors. Here's how it works by Gregor Aisch.

Example

The colorblindcheck accepts a vector of hexadecimal color descriptions as the input. It can be created using different existing R functions (e.g. rainbow()) or packages (e.g. colorspace, RColorBrewer, rcartocolor, etc.).

library(colorblindcheck)
rainbow_pal = rainbow(n = 7)
rainbow_pal

The primary function in this package is palette_check(), which creates a summary comparison between the original input palette and simulations of color vision deficiencies - deuteranopia, protanopia, and tritanopia.

palette_check(rainbow_pal, plot = TRUE)

The palette_check() function returns a data.frame with 4 observations and 8 variables:

Additionally, a plot comparing the original input palette and simulations of color vision deficiencies - deuteranopia, protanopia, and tritanopia can be shown. This help to decide if the selected color palette is colorblind friendly.

For example, the above output shows that the minimal distance between colors in the input palette is about 12; however, the minimum distance between colors simulation of tritanopia is only about 2. It can suggest that some colors in this palette would not be distinguishable by people with color vision deficiencies.

The palette_dist() function calculates distances between the colors in the input palette, as well as in a simulation of the selected color vision deficiency - deuteranopia, protanopia, and tritanopia. It allows finding which colors are the most or the least similar and to compare the behavior of color palettes for different color vision deficiencies. In the original rainbow_pal object, the closest colors were the third and the fourth one (a distance of about 12); however, the deuteranopia version has a minimal distance of 3 between the second and third color.

# normal
palette_dist(rainbow_pal)
# deuteranopia
palette_dist(rainbow_pal, cvd = "pro")


Try the colorblindcheck package in your browser

Any scripts or data that you put into this service are public.

colorblindcheck documentation built on May 31, 2023, 8:08 p.m.