color_dissimilarity

Measure the similarity of colors in a palette, and choose dissimilar colors from them.
git clone https://git.eamoncaddigan.net/color_dissimilarity.git
Log | Files | Refs | README | LICENSE

demo.Rmd (1474B)


      1 ---
      2 title: "Demonstrations"
      3 author: "Eamon Caddigan"
      4 date: "9/4/2021"
      5 output: html_document
      6 ---
      7 
      8 ```{r setup, include=FALSE}
      9 knitr::opts_chunk$set(echo = TRUE)
     10 ```
     11 
     12 First, make sure we have the libraries we need and import the R scripts.
     13 
     14 ```{r}
     15 library(colorspace)
     16 library(grDevices)
     17 ```
     18 ```{r}
     19 source('dissimilarity.R')
     20 source('seq_dissim_colors.R')
     21 source('color_utils.R')
     22 set.seed(271191508)
     23 ```
     24 ```{r}
     25 compare_colors <- function(cols, cvd_function = identity) {
     26   colorspace::swatchplot(cols,
     27                          RGB2hex(apply_cvd(col2RGB(cols), cvd_function)))
     28 }
     29 ```
     30 
     31 Next let's grab some random colors and show them.
     32 
     33 ```{r}
     34 some_colors <- c('red', 'black', 'white', 'khaki', 'gray50',
     35                  '#a6cee3', '#1f78b4', '#b2df8a', '#33a02c')
     36 #some_colors <- paste0("gray", round(seq(10, 90, length.out = 13)))
     37 #some_colors <- colorRampPalette(c("gray10", "gray90"), space = "Lab")(6)
     38 some_colors <- sample(some_colors)
     39 colorspace::swatchplot(some_colors)
     40 ```
     41 
     42 Here's the mild deuteranomaly we're using for the default color comparison (it's more extreme than my own).
     43 
     44 ```{r}
     45 compare_colors(some_colors, function(x) colorspace::deutan(x, 0.5))
     46 ```
     47 
     48 And here's the dissimilarity matrix of the colors.
     49 
     50 ```{r}
     51 dissim_mat <- cvd_dissimilarity(some_colors, "none")
     52 image(dissim_mat)
     53 ```
     54 
     55 Let's look at sets of dissimilar colors from the palette.
     56 
     57 ```{r}
     58 colorspace::swatchplot(some_colors,
     59                        some_colors[seq_dissim_colors(dissim_mat)])
     60 ```