Skip to contents

This function generates a palette of distinct colors that maximizes differences between adjacent colors. It uses the HSV color space to create a visually appealing and distinguishable set of colors.

Usage

create_distinct_palette(n)

Arguments

n

An integer specifying the number of distinct colors to generate.

Value

A character vector of hex color codes.

Details

Create a Palette of Distinct Colors

The function creates colors by:

  • Using the full range of hues (0-1)

  • Keeping saturation relatively high (0.7-1)

  • Alternating value (brightness) between higher and lower values (0.6-0.9)

Hues are shuffled to avoid similar adjacent colors.

Examples

if (FALSE) { # \dontrun{
# Generate a palette of 10 distinct colors
colors <- create_distinct_palette(10)
# Use the colors in a plot
plot(1:10, 1:10, col = colors, pch = 19, cex = 3)
} # }