random_n_colours | R Documentation |
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"""
random_n_colours(num, hex = TRUE)
num |
Number of colours to generate |
hex |
TRUE/FALSE for hexademical colours [Default = TRUE] |
A vector of colours, either hexadecimal or named colours
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"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.