match_colors: Reorder a color palette to best match a reference palette

View source: R/reorder_colors.R

match_colorsR Documentation

Reorder a color palette to best match a reference palette

Description

Often for batch processing purposes, it is important to ensure that color centers fit using different methods are in the same order. This function reorders a provided color palette (match_palette) according a provided reference palette (reference_palette) by minimizing their overall distance using the Hungarian algorithm as implemented by clue::solve_LSAP.

Usage

match_colors(reference_palette, match_palette, plotting = FALSE)

Arguments

reference_palette

The palette whose order to match. Either a character vector of colors (hex codes or color names) or an nx3 matrix in sRGB color space.

match_palette

The palette to reorder, same formats as reference_palette

plotting

Logical. Plot the ordered palettes?

Details

If the color palettes are wildly different, the returned order may not be especially meaningful.

Value

A vector of color orders for match_palette.

See Also

reorder_colors

Examples

ref_palette <- c("mediumblue", "olivedrab", "tomato2", "beige", "chocolate4")
match_palette <- c("#362C34", "#E4D3A9", "#AA4E47", "#809C35", "#49468E")
match_colors(ref_palette, match_palette, plotting = TRUE)


hiweller/recolorize documentation built on March 29, 2025, 4:15 a.m.