Skip to contents

Helpful for pairing colors across light/dark palettes

Usage

color_match(x, y, with_replacement = TRUE)

Arguments

x

chr Named CSS representations of colors that will be matched

y

chr Named CSS representations of colors that will be selected from as matches

with_replacement

lgl Whether colors in x should have unique matches in y, or if y can be matched with replacement. Default TRUE to match with the closest color in y, regardless if it's already been matched with a previous color in x.

Value

tbl Of matches for all of x with the associated distance

Examples

a <- list(
  light = list(
    aquamarine = "rgb(137,210,215)",
    teal = "rgb(79,194,198)",
    turquoise = "rgb(3,119,132)",
    evergreen = "rgb(0,84,92)",
    brown = "rgb(72,36,18)",
    lightbrown = "rgb(132,96,78)",
    orange = "rgb(250,173,25)",
    darkorange = "rgb(198,143,44)",
    aliceblue = "rgb(180,243,249)",
    gainsboro = "rgb(223,254,255)"
  ),
  dark = list(
    lightblue = "rgba(18,180,211,1)",
    darkblue = "rgba(2,120,170,1)",
    navyblue = "rgba(0,57,73,1)",
    brown = "rgba(72,36,18,1)",
    lightbrown = "rgb(132,96,78)",
    lighterbrown = "rgba(181,141,122, 1)",
    purple = "rgba(111,96,140,1)",
    lightpurple = "rgba(165,150,194,1)",
    darkcyan = "rgba(0,166,212,1)",
    darkturquoise = "rgba(9,119,168,1)"
  )
)
color_match(a$light, a$dark)
#> # A tibble: 10 × 5
#>    x                x_nm       y                  y_nm            dist
#>    <chr>            <chr>      <chr>              <chr>          <dbl>
#>  1 rgb(137,210,215) aquamarine rgba(18,180,211,1) lightblue     1010. 
#>  2 rgb(79,194,198)  teal       rgba(18,180,211,1) lightblue      393. 
#>  3 rgb(3,119,132)   turquoise  rgba(9,119,168,1)  darkturquoise  141. 
#>  4 rgb(0,84,92)     evergreen  rgba(0,57,73,1)    navyblue       910. 
#>  5 rgb(72,36,18)    brown      rgba(72,36,18,1)   brown            0  
#>  6 rgb(132,96,78)   lightbrown rgb(132,96,78)     lightbrown       0  
#>  7 rgb(250,173,25)  orange     rgba(18,180,211,1) lightblue      736. 
#>  8 rgb(198,143,44)  darkorange rgba(0,166,212,1)  darkcyan        89.6
#>  9 rgb(180,243,249) aliceblue  rgba(18,180,211,1) lightblue     2046. 
#> 10 rgb(223,254,255) gainsboro  rgba(18,180,211,1) lightblue     2520.