View source: R/reorder_colors.R
reorder_colors | R Documentation |
Often for batch processing purposes, it is important to ensure that color centers fit using different methods are in the same order.
reorder_colors(recolorize_obj, col_order, plotting = FALSE)
recolorize_obj |
An object of class |
col_order |
A numeric vector of the length of the number of color
centers in the |
plotting |
Logical. Plot the results? |
While you can manually specify the col_order
vector, one way to
automatically order the colors according to an external color palette (as
might be needed for batch processing) is to use the match_colors function,
although it is recommended to double-check the results.
A recolorize
object.
img <- system.file("extdata/corbetti.png", package = "recolorize")
rc <- recolorize2(img, cutoff = 45)
ref_palette <- c("mediumblue", "olivedrab", "tomato2", "beige", "grey10")
col_order <- match_colors(ref_palette, rc$centers, plotting = TRUE)
rc2 <- reorder_colors(rc, col_order, plotting = FALSE)
# the colors are reordered, but not changed to match the reference palette:
plot(rc2)
# you can also change them to the reference palette:
rc2$centers <- t(grDevices::col2rgb(ref_palette) / 255)
plot(rc2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.