sort_colors: Sort a vector of colors using one or more color attributes

sort_colorsR Documentation

Sort a vector of colors using one or more color attributes

Description

Sort a vector of colors using one or more color attributes

Usage

sort_colors(
  x,
  ...,
  alpha = TRUE,
  byCols = c("H", "C", "L"),
  return_type = c("colors", "df")
)

Arguments

x

character vector of R colors

...

any valid criteria to subset the color data.frame.

alpha

logical indicating whether to retain alpha transparency in intermediate operations. When alpha=FALSE then all color transparency is ignored, and colors will be returned with no transparency.

byCols

character vector of colnames to sort after the subset operation.

return_type

character string to define the return object, where return_type="colors" returns a character vector of colors, and return_type="df" returns a data.frame with the additional subset colnames included for review.

Details

This function is an extension of subset_colors() except that it applies a sort order to the results.

The input colors in x are converted internally to a data.frame with colnames added by relevant helper functions.

  • "num" contains the integer index of the input vector x.

  • "hex" contains character values with hexadecimal colors including alpha. If the input x is "red" then the hex value will be converted to "#FF0000FF".

Value

character vector of colors that meet the filter criteria. When return_type="df" the returned object is a data.frame with the subset columns included for review.

Added by jamba::col2hcl()

  • "H" contains color hue as values from 0 to 360.

  • "C" contains color chroma (aka saturation) ranging from 0 up to 200, where typical "full saturation" is represented as values above 100.

  • "L" contains color luminance (brightness/lightness) ranging from 0 to 100.

  • "alpha" the alpha transparency, ranging from 0 (fully transparent) to 1 (fully opaque, not transparent).

Added by grDevices::col2rgb()

  • "red" contains the red color channel, values range from 0 to 255.

  • "green" contains the green color channel, values range from 0 to 255.

  • "blue" contains the blue color channel, values range from 0 to 255.

Added by jamba::col2hsv()

  • "h" contains color hue as values from 0 to 1. Note these values may not map directly to color hue obtained from jamba::col2hcl().

  • "s" contains color saturation with values from 0 to 1.

  • "v" contains color vibrance (brightness/lightness) with values from 0 to 1.

See Also

Other colorjam sort: colors_to_df(), subset_colors()

Other colorjam core: blend_colors(), closestRcolor(), closest_named_color(), color_complement(), colors_to_df(), group2colors(), rainbowJam(), subset_colors()

Examples

# subset for blue colors
jamba::showColors(subset_colors(colors(), H > 200 & H < 265 & C > 80))

# subset for saturated colors
jamba::showColors(subset_colors(colors(), C > 120))

# subset for saturated colors then sort by hue
jamba::showColors(subset_colors(colors(), C > 120, byCols=c("H", "-C", "-L")))

# review the data.frame itself
subset_colors(colors(), C > 135, return_type="df")

# for curiosity, compare H to h
colors_df <- subset_colors(colors(),
   C > 20,
   byCols=c("C"),
   return_type="df");
plot(colors_df$h, colors_df$H,
   xlab="hsv hue h",
   ylab="HCL hue H",
   pch=20,
   cex=colors_df$s * 1 + 1,
   col=colors_df$hex);
title("Comparison of HCL hue H\nwith hsv hue h")

plot(colors_df$s, colors_df$C,
   xlab="hsv saturation s",
   ylab="HCL chroma C",
   pch=20,
   cex=colors_df$s * 1 + 1,
   col=colors_df$hex);
title("Comparison of HCL C\nwith hsv s")

plot(colors_df$v, colors_df$L,
   xlab="hsv vibrance v",
   ylab="HCL luminance L",
   pch=20,
   cex=colors_df$s * 1 + 1,
   col=colors_df$hex);
title("Comparison of HCL L\nwith hsv v")


jmw86069/colorjam documentation built on March 18, 2024, 3:32 a.m.