0

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.

Prradep
  • 5,506
  • 5
  • 43
  • 84
  • @Henrik After doing my homework, I have posted this question to find a better possible solution. The `color.names(rainbow(4))` in the [link](https://stackoverflow.com/a/28461584/4836511) gives only 2 out of 4 color names. As getting nearly 100% color names is highly important, I have requested for any possible elegant solutions. – Prradep Jul 13 '17 at 19:34
  • For the best possible solution arrived in the discussion: https://stackoverflow.com/a/45090183/4836511 – Prradep Jul 13 '17 at 20:29

0 Answers0