How do I choose 4-8 colors in base R for plots that colorblind people will be able to see?
Below is the base R color pallet. Looking for a solution in BASE R without the use of packages.
Base R Color Palette Guide: http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf
Color Palettes for Color Blindness: http://mkweb.bcgsc.ca/colorblind/
Specifically how do I manually create accessible colors in BASE R?
e.g. "vermilion", "bluish green", and "reddish purple" as described in the paper figure below.
Use a colorblind-friendly palette when appropriate For example, blue/orange is a common colorblind-friendly palette. Blue/red or blue/brown would also work. For the most common conditions of CVD, all of these work well, since blue would generally look blue to someone with CVD.
The first rule of making a palette for colorblind – avoid combining red and green. So if you're aiming to create a color blind-friendly palette try to use only two basic hues: blue and red (orange and yellow will also fit). The other colors should be made out of these two hues.
Avoid bad color combos That being said, here's a few color combinations to avoid because they're a potential nightmare to color blind users: Green & Red. Green & Brown. Blue & Purple.
These are the hex codes for those colors in the image you posted
colorBlindBlack8 <- c("#000000", "#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00", "#CC79A7")
pie(rep(1, 8), col = colorBlindBlack8)
colorBlindGrey8 <- c("#999999", "#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00", "#CC79A7")
scales::show_col(colorBlindGrey8)
For more than 8 colors, rcartocolor
has the Safe
palette with 12 colors
safe_colorblind_palette <- c("#88CCEE", "#CC6677", "#DDCC77", "#117733", "#332288", "#AA4499",
"#44AA99", "#999933", "#882255", "#661100", "#6699CC", "#888888")
scales::show_col(safe_colorblind_palette)
If you need sequential or diverging colormaps, check these palettes out
library(rcartocolor)
display_carto_all(colorblind_friendly = TRUE)
Created on 2019-07-22 by the reprex package (v0.3.0)
The palette shown in the question is also known as the Okabe-Ito palette as suggested by Okabe & Ito (2008). Since version 4.0.0, base R provides a new palette.colors()
where this palette is actually the default:
palette.colors(palette = "Okabe-Ito")
## black orange skyblue bluishgreen yellow
## "#000000" "#E69F00" "#56B4E9" "#009E73" "#F0E442"
## blue vermillion reddishpurple gray
## "#0072B2" "#D55E00" "#CC79A7" "#999999"
Along with this palette, various other qualitative palettes are easily available in base R. Specifically, the new default palette (called "R4"
) has also been designed to be rather robust under color vision deficiencies. See this blog post for further details:
In addition to the qualitative palettes above, base R also has a new function hcl.colors()
since version 3.6.0 that makes many sequential and diverging palettes available that are also robust under color vision deficiencies. It provides approximations (derived using the hue-chroma-luminance color model) to many palettes from ColorBrewer.org, viridis, CARTO colors, Crameri's scientific colors etc. The default is the popular viridis palette. The following blog post provides more details and the paper about the colorspace
package explains more related/underlying work.
The color scales in the viridis
package are all color blind accessible. https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html#the-color-scales
If you need to use colors by name like in the pdf you linked to, match colors from the viridis
palettes to the named list of colors. For 4-8, this is pretty easy to do visually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With