I would like to select distinct colors for the levels available in a factored column.
levels(iris$Species)
# [1] "setosa" "versicolor" "virginica"
From this question, I found that selecting distinct colors using the brewer.pal
function is optimal and/or easy. I have identified the solution as
data.frame(values=levels(iris$Species),
colhex=brewer.pal(3,'Accent'))
# values colhex
# 1 setosa #7FC97F
# 2 versicolor #BEAED4
# 3 virginica #FDC086
However, I would like to map these hex codes to color names as (expected output):
# values colhex colnames
# 1 setosa #7FC97F color1
# 2 versicolor #BEAED4 color2
# 3 virginica #FDC086 color3
How to achieve this mapping?
Alternatively, is there any package which provides the color names with hex codes for n
(say n=85+
) distinct values.
There is another way to identify the colors present, using:
r_colors <- cbind(colors(), t(col2rgb(colors())))
I feel this approach is difficult to identify the n
distinct possible colors.