Find color names for colors close to colorBrewer palette

こ雲淡風輕ζ 提交于 2019-12-03 12:59:53

See if this is useful. (It's an LI distance on rgb space):

col.dist <- function(inp, comp) sum( abs(inp - col2rgb(comp) ) )

colors()[ apply(col2rgb(brew10), 2, 
             function(z) which.min( sapply(colors(), 
                           function(x) col.dist(inp=z, comp=x) ) ) ) ]
#-----------
 [1] "paleturquoise3"  "moccasin"        "lightsteelblue"  "salmon" 
 [5] "lightskyblue3"   "sandybrown"      "darkolivegreen2" "thistle2"
 [9] "gray85"          "orchid3"   

Looks like it might have succeeded looking at:

display.brewer.pal(10,"Set3")

(Although I have never see a thistle that color, and I would have thought number 7 to be more of a "lightolive" than a "darkolive".) You would proably get faster response, although this seemed acceptable, if you made the call to colors once and stored that matrix.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!