Color blindness is color vision deficiency, which means people with color blindness may be not aware of differences among colors that are obvious to the people without it. This package is designed to provide a collection of safe colors for plots such as heatmaps, pie chart, and try to find a solution for acceptable figures for all the end users.
There are lots of packages already collected lots of safe colors. I list some of them, but not limited here.
For this package, I will try to collect as much as possible safe color sets ready to use.
The tool used to simulate the color vision deficiency is called CVD simulator. I list some of packages here with CVD simulator.
Hans Brettel 1997(Brettel et al., 1997)
Francoise Vienot 1999(Viénot et al., 1999) (implemented in this package and package dichromat )
Gustavo M. Machado 2009(Machado et al., 2009) (implemented in package colorspace)
Claire D. McWhite and Claus O. Wilke. colorblindr
To plot figures by colors of this package, there are three steps:
select correct safe color set.
plot with the color set.
check the plot by CVD simulator.
For example if we want to plot a heatmap.
library(colorBlindness)
mat <- matrix(1:81, nrow = 9, ncol = 9)
library(ggplot2)
library(reshape2)
mat1 <- melt(t(mat[9:1, ]))
len <- length(Blue2DarkRed12Steps)-1
mat1$v2 <- cut(mat1$value,
breaks = seq(0,ceiling(81/len)*len,
length.out = len+1))
ht <- ggplot(mat1) +
geom_tile(aes(x=Var1, y=Var2, fill=v2)) +
scale_fill_manual(values=Blue2DarkRed12Steps) +
theme_bw()
# check the plot by CVD simulator
cvdPlot(ht)
If you have figures which is not safe to color blindness people, you
can try to replace the colors by replacePlotColor
function.
If you have a fluorescence image and want to change the colors, you can read the figure and view the effect of color changed figure. If it is acceptable, you can draw it into a file.
library(grid)
library(png)
path <- system.file("extdata", package = "colorBlindness")
img <- readPNG(file.path(path, "fluorescence.microscopy.images.png"))
g <- rasterGrob(img, interpolate=TRUE)
grid.draw(cvdPlot(g,
layout = c("origin", "deuteranope", "protanope",
"enhanced", "enhanced.deuteranope",
"enhanced.protanope")))
newImg <- replacePlotColor(g)
outfile <- tempfile(fileext = ".png")
png(outfile)
grid.draw(newImg)
dev.off()
## png
## 2
To plot figures for literature, there serveral things we need to consider:
Figure format and size;
Font family and size;
Proper figure colors that are distinguishable by people with colorblindness and for printed in black and white.
setPDFopt
function can provide you preset figure size
for PDF outputs.
## $width
## [1] 7
##
## $height
## [1] 7
##
## $pointsize
## [1] 12
## $width
## 1col
## 3.54
##
## $height
## 1col
## 3.54
##
## $pointsize
## [1] 8
There are more than 15 Color palettes for color blindness from Martin Krzywinski and et al.
See also GETTING INTO VISUALIZATION OF LARGE BIOLOGICAL DATA SETS and “Controversial Color Use on Maps”(Brewer, 1997).
The displayAllColors
funciton can be used to show the
effect for color vision deficiency. Here we dispaly color collection
from Bang Wong(Wong, 2011).
replacePlotColor
effect for Ishihara Color Test.## replace the color of a file
ishihara29 <- system.file("extdata", "Plate3.png", package = "colorBlindness")
library(png)
img <- readPNG(ishihara29)
g <- rasterGrob(img, interpolate=TRUE)
grid.draw(cvdPlot(g,
layout = c("origin", "deuteranope", "protanope",
"enhanced", "enhanced.deuteranope",
"enhanced.protanope")))
## R version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Etc/UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] grid stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] png_0.1-8 reshape2_1.4.4 ggplot2_3.5.1
## [4] colorBlindness_0.1.9
##
## loaded via a namespace (and not attached):
## [1] gtable_0.3.6 jsonlite_1.8.9 highr_0.11 compiler_4.4.1
## [5] Rcpp_1.0.13 stringr_1.5.1 gridGraphics_0.5-1 jquerylib_0.1.4
## [9] scales_1.3.0 yaml_2.3.10 fastmap_1.2.0 R6_2.5.1
## [13] plyr_1.8.9 labeling_0.4.3 knitr_1.48 tibble_3.2.1
## [17] maketools_1.3.1 munsell_0.5.1 bslib_0.8.0 pillar_1.9.0
## [21] rlang_1.1.4 utf8_1.2.4 stringi_1.8.4 cachem_1.1.0
## [25] xfun_0.49 sass_0.4.9 sys_3.4.3 cli_3.6.3
## [29] withr_3.0.2 magrittr_2.0.3 digest_0.6.37 cowplot_1.1.3
## [33] lifecycle_1.0.4 vctrs_0.6.5 evaluate_1.0.1 glue_1.8.0
## [37] farver_2.1.2 buildtools_1.0.0 fansi_1.0.6 colorspace_2.1-1
## [41] rmarkdown_2.28 tools_4.4.1 pkgconfig_2.0.3 htmltools_0.5.8.1