simcol: Find similar colors

View source: R/color_fun_2.R

simcolR Documentation

Find similar colors

Description

simcol finds and shows colors from a palette of color candidates col_candidates that are similar to some target color col_target.

Usage

simcol(
  col_target,
  col_candidates = colors(),
  tol = c(25, 50, 75),
  distinct = TRUE,
  plot = TRUE
)

Arguments

col_target

A (required) target color.

col_candidates

A palette of color candidates to be considered. Default: col_candidates = colors().

tol

Numeric tolerance value(s) (either 1 or 3 numeric values, in the RGB range from 0 to 255). Values are considered in the order of the RGB value rank in col_target. Default: tol = c(25, 50, 75).

distinct

Boolean: Return only visually distinct colors? Default: distinct = TRUE (i.e., remove visual duplicates).

plot

Boolean: Plot the output (using seecol)? Default: plot = TRUE.

Details

simcol returns a vector of the (named) colors or color values in col_candidates (set to colors() of grDevices per default) that are similar to the specified target color col_target.

If plot = TRUE, simcol also visualizes the detected colors (by passing its result to seecol, as a side-effect).

Color similarity is defined in terms of the distance between colors' RGB values, which must be within the numeric tolerance threshold(s) specified by tol (with 0 <= tol <= 255). Higher tol values correspond to more permissive similarity judgments.

If tol is a scalar, the values of all three RGB dimensions of col_candidates must be within the corresponding values of col_target to be judged as 'similar'. If tol contains three values, the three RGB dimension are compared in order of the dimensions' rank in col_target (i.e., the primary dimension must be within tol[1], etc.). Thus, providing three tol values allows for more fine-grained similarity matching.

Value

A named vector of colors or color values.

See Also

seecol for plotting/seeing color palettes; usecol for using color palettes; newpal for defining new color palettes; grepal for finding named colors; shades_of to defining shades of a given color; ac for adjusting color transparency.

Other color functions: ac(), demopal(), grepal(), newpal(), seecol(), shades_of(), usecol()

Examples

# Basic uses:
simcol(col_target = "red")
simcol("tan", tol = 15)
simcol(Seeblau, tol = c(20, 30, 40))
simcol("blue", col_candidates = pal_unikn_pref, tol = 120)

# Fine-tuning the range of color matching:
simcol(Seeblau, tol = 30)  # = simcol(Seeblau, tol = c(30, 30, 30))
simcol(Seeblau, tol = c(20, 20, 80))

# Increasing tolerance widens range:
simcol("grey", c("white", "grey", "black"), tol = 255, distinct = FALSE, plot = FALSE)


unikn documentation built on May 29, 2024, 10:41 a.m.