Group Hex Colors. This function takes a vector of hex color values and groups them using k-means clustering in the RGB color space. It returns a data frame with the original hex colors and their assigned group labels.

groupCols(hex_colors, n_clusters = 5)

Arguments

hex_colors

A character vector of hex color values.

n_clusters

The number of clusters (groups) to use in the k-means clustering. Default is 5.

Value

A data frame with the original hex colors and their assigned group labels.

Examples

hex_colors <- c("#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#FF00FF")
groupCols(hex_colors, n_clusters = 2)
#>   hex_color group
#> 2   #00FF00     2
#> 3   #0000FF     2
#> 1   #FF0000     1
#> 4   #FFFF00     1
#> 5   #FF00FF     1