spsanderson / healthyR.ai

healthyR.ai - AI package for the healthyverse
http://www.spsanderson.com/healthyR.ai/
Other
16 stars 6 forks source link

red/green color blindness #219

Closed earosenthal closed 2 years ago

earosenthal commented 2 years ago

I noticed that you used red/green on your PCA loadings and variance explained plots. About 8% of the male population has red/green color blindness. I recommend that you use colors that are easier to distinguish. Here is one example that could help: https://cran.r-project.org/web/packages/colorBlindness/vignettes/colorBlindness.html

spsanderson commented 2 years ago

Functions:

#' Provide Colorblind Compliant Colors 
#' 
#' 8 Hex RGB color defintions suitable for charts for colorblind people.
#' 
#' @export
color_blind <- function(){
  c("#000000", "#E69F00", "#56B4E9",
    "#009E73", "#F0E442", "#0072B2",
    "#D55E00", "#CC79A7")
}

# Fill
ts_scale_fill_colorblind = function(.ColorList = 2L:8L, ...){
  ggplot2::scale_fill_discrete(..., type = color_blind())
}

# Color
ts_scale_color_colorblind = function(.ColorList = 2L:8L, ...){
  ggplot2::scale_color_discrete(..., type = color_blind())
}

Example:

library(tidyverse)

ggplot(
  diamonds,
  aes(clarity, fill = cut)
) +
  geom_bar(position = "dodge") +
  ts_scale_fill_colorblind()

image

spsanderson commented 2 years ago

https://stackoverflow.com/questions/19300134/ggplot2-with-colour-blind-ggthemes-except-black