Last active
January 17, 2020 13:43
-
-
Save ikashnitsky/9ec271ba819479fb9b748e2e5c10b040 to your computer and use it in GitHub Desktop.
Safe and efficient palette of five colors for R -- https://twitter.com/ikashnitsky/status/1200570023334559745
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#=============================================================================== | |
# 2019-11-30 -- gist | |
# Safe and efficient palette of five colors, print and colorblind friendly | |
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com | |
#=============================================================================== | |
library(magrittr) | |
library(prismatic) | |
# a function to test color paletes quickly | |
test_color <- function(color_vec) { | |
require(magrittr) | |
require(prismatic) | |
par(mfrow = c(2,3), mai = c(0, 0, .5, 0)) | |
color_vec %>% color %>% plot; title("Color palette") | |
color_vec %>% color %>% clr_grayscale %>% plot; title("Grayscale") | |
color_vec %>% color %>% clr_negate %>% plot; title("Negate") | |
color_vec %>% color %>% clr_protan %>% plot; title("Protan") | |
color_vec %>% color %>% clr_deutan %>% plot; title("Deutan") | |
color_vec %>% color %>% clr_tritan %>% plot; title("Tritan") | |
par(mfrow = c(1,1)) | |
} | |
# a selection of 5 colors, print and colorblind friendly | |
pal_safe_five <- c( | |
"#eec21f", # default R 4.0 yellow | |
"#009C9C", # light shade of teal: no red, equal green and blue | |
"#df356b", # default R 4.0 red | |
"#08479A", # blues9[8] "#08519C" made a bit darker | |
"#003737" # very dark shade of teal | |
) | |
pal_safe_five %>% test_color() | |
# a selection of 6 colors, print and colorblind friendly | |
pal_safe_six <- c( | |
"#eec21f", | |
"#3FB3F7", | |
"#268A8A", | |
"#A14500", | |
"#084488", | |
"#003737" | |
) | |
pal_safe_six %>% test_color() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment