colorblindr icon indicating copy to clipboard operation
colorblindr copied to clipboard

Just checking - no continuous functionality?

Open jzadra opened this issue 4 years ago • 2 comments

I juist wanted to confirm that this package doesn't support continuous scales? I'm not missing anything?

jzadra avatar Nov 14 '19 21:11 jzadra

@jzadra, ran across this question while looking for an option to produce more than 8 colors. In my case, I ended up putting together this hacky fix for creating a lengthier palette based on the colorblindr defaults. Once the palette is generated, then it can be inserted into ggplot with scale_fill_manual(values = colorblindr_cont).

When my monitor is set to grayscale it seems to generally maintain the desired colorblindr differentiation. Maybe this will work for your needs or be easily adjusted if not?

library(RColorBrewer)

gen_palette <- function(data, var){
  n_colors <- length(unique(data[, var])) # number of unique values for var
  color_pal <- c(
    "#E69F00", "#56B4E9", "#009E73", "#F0E442",
    "#0072B2", "#D55E00", "#CC79A7", "#000000"
  )
  custom_colors <- colorRampPalette(color_pal)(n_colors)
  return(custom_colors)
}

colorblinr_cont <- gen_palette(data = dataset, var = "varname")

dnkent avatar Jan 20 '21 01:01 dnkent

Thanks!

jzadra avatar Jan 20 '21 04:01 jzadra