How to Generate a Palette of Distinct Colors in R (Example Code)
In this R tutorial you’ll learn how to create a range of different hex color codes.
Example: Creating Palette of Different Colors Using rainbow() Function
number_of_col <- 30 # Defining number of colors |
number_of_col <- 30 # Defining number of colors
set.seed(964294) # Setting random seed my_cols <- sample(rainbow(number_of_col)) # Applying rainbow() function my_cols # Showing hex color codes in RStudio console # [1] "#00FF33" "#FF0099" "#FF6600" "#6600FF" "#FFFF00" "#99FF00" "#0099FF" "#FF3300" ... |
set.seed(964294) # Setting random seed my_cols <- sample(rainbow(number_of_col)) # Applying rainbow() function my_cols # Showing hex color codes in RStudio console # [1] "#00FF33" "#FF0099" "#FF6600" "#6600FF" "#FFFF00" "#99FF00" "#0099FF" "#FF3300" ...
pie(rep(1, number_of_col), col = my_cols) # Drawing pie chart with colors |
pie(rep(1, number_of_col), col = my_cols) # Drawing pie chart with colors