random_n_colours: Create a vector of "n" random colours

View source: R/colours.R

random_n_coloursR Documentation

Create a vector of "n" random colours

Description

Create a vector of "n" random colours using grDevices, output either hexadecimal/named colours Code to generate list of all colors to sample from taken from: """https://stackoverflow.com/questions/15282580/how-to-generate-a-number-of-most-distinctive-colors-in-r"""

Usage

random_n_colours(num, hex = TRUE)

Arguments

num

Number of colours to generate

hex

TRUE/FALSE for hexademical colours [Default = TRUE]

Value

A vector of colours, either hexadecimal or named colours

Examples

random_n_colours(10, TRUE)
random_n_colours(num = 20, hex = FALSE)

#Names can be set to vector afterwards (e.g. to create a named set of colours to pass to ggplot2, such as scale_fill_manual())
#For example:
colours_vector <- random_n_colours(3, TRUE) # first get a vector of three hex colours
names(colours_vector) <- c("first_name","second_name","third_name") # then apply the names

Example output:
 first_name second_name  third_name
  "#CDC9A5"   "#6959CD"   "#D2691E"

djw533/micro.gen.extra documentation built on Nov. 8, 2024, 5:11 a.m.