Skip to contents

Analyze a categorical color palette with respect to the differences between the colors in the palette.

Usage

analyze_palette(
  palette,
  cvd = c(protan = 0, deutan = 0, tritan = 0),
  bg = NULL,
  metric = c("ciede2000", "din99d", "cie76")
)

Arguments

palette

Either a matrix of RGB values (with values between 0 and 1), a data frame with RGB values, or a character vector of hex colors.

cvd

Color vision deficiency adaptation. This must be a named vector with names protan, deutan, and tritan and values between 0 and 1, where 0 means no adaptation and 1 means full adaptation.

bg

Background color to consider (but not include) when generating the palette. This is useful to avoid colros that are too close to the background/canvas color. If NULL (the default), the background color is not considered at all. Any color that is convertable via col2rgb is acceptable, including hex colors.

metric

The color metric to use for the color distance matrix.

Value

A list of lists, one for each type of color vision deficiency plus normal vision. Each list contains difference_matrix, min_distances, and bg_min_distance

See also

Examples

pal <- qualpal(5)
analyze_palette(pal$hex, cvd = c(protan = 1))
#> $deutan
#> $deutan$difference_matrix
#>          #c8cb70  #7bc4cc  #cb7469  #6d6cc9
#> #7bc4cc 31.92168                           
#> #cb7469 41.59276 43.76051                  
#> #6d6cc9 64.31978 33.48929 35.21757         
#> #d7c3e9 45.21912 31.43774 30.05420 29.97800
#> 
#> $deutan$min_distances
#>  #c8cb70  #7bc4cc  #cb7469  #6d6cc9  #d7c3e9 
#> 31.92168 31.43774 30.05420 29.97800 29.97800 
#> 
#> $deutan$bg_min_distance
#> [1] NaN
#> 
#> 
#> $normal
#> $normal$difference_matrix
#>          #c8cb70  #7bc4cc  #cb7469  #6d6cc9
#> #7bc4cc 31.92168                           
#> #cb7469 41.59276 43.76051                  
#> #6d6cc9 64.31978 33.48929 35.21757         
#> #d7c3e9 45.21912 31.43774 30.05420 29.97800
#> 
#> $normal$min_distances
#>  #c8cb70  #7bc4cc  #cb7469  #6d6cc9  #d7c3e9 
#> 31.92168 31.43774 30.05420 29.97800 29.97800 
#> 
#> $normal$bg_min_distance
#> [1] NaN
#> 
#> 
#> $protan
#> $protan$difference_matrix
#>           #c8cb70   #7bc4cc   #cb7469   #6d6cc9
#> #7bc4cc 31.794395                              
#> #cb7469 26.259368 26.871922                    
#> #6d6cc9 57.422891 26.634673 36.610806          
#> #d7c3e9 38.360173  6.724315 33.522738 26.562888
#> 
#> $protan$min_distances
#>   #c8cb70   #7bc4cc   #cb7469   #6d6cc9   #d7c3e9 
#> 26.259368  6.724315 26.259368 26.562888  6.724315 
#> 
#> $protan$bg_min_distance
#> [1] NaN
#> 
#> 
#> $tritan
#> $tritan$difference_matrix
#>          #c8cb70  #7bc4cc  #cb7469  #6d6cc9
#> #7bc4cc 31.92168                           
#> #cb7469 41.59276 43.76051                  
#> #6d6cc9 64.31978 33.48929 35.21757         
#> #d7c3e9 45.21912 31.43774 30.05420 29.97800
#> 
#> $tritan$min_distances
#>  #c8cb70  #7bc4cc  #cb7469  #6d6cc9  #d7c3e9 
#> 31.92168 31.43774 30.05420 29.97800 29.97800 
#> 
#> $tritan$bg_min_distance
#> [1] NaN
#> 
#>