查找接近colorBrewer调色板的颜色的颜色名称 [英] Find color names for colors close to colorBrewer palette

查看:221
本文介绍了查找接近colorBrewer调色板的颜色的颜色名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用R包SNA进行社交网络分析。 SNA仅使用R颜色名称(文本名称)为元素上色。

I want to use the R package SNA to do social network analysis. SNA colors elements only using R color names (text names).

我想查找从ColorBrewer调色板(set3)到R中颜色名称的近似匹配项。

I'd like to find near matches from a ColorBrewer palette (set3) to the color names in R.

在RGB空间中没有很多精确匹配项。

There aren't many exact matches in the RGB space.

require(RColorBrewer) 
brew10 <- brewer.pal(10, "Set3")
rcol <- colors()
brew10rgb <- col2rgb(brew10)
allrgb <- col2rgb(rcol)
apply(t(brew10rgb), 1, paste, collapse="$$") %in% apply(t(allrgb), 1, paste,collapse="$$")
brew10rgb[,1]
fltr <- allrgb[1,]==141
allrgb[,fltr]
fltr <- allrgb[2,]==211
allrgb[,fltr]

是否可以选择一种好的颜色名称定性调色板,还是将这些RColorBrewer颜色映射到现有颜色?

Is there a way to pick good color names for a qualitative palette in R, or to map these RColorBrewer colors to existing colors?

推荐答案

看看这是否有用。 (这是rgb空间上的LI距离):

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")


(尽管我从未见过这种颜色的蓟,但我本来以为7号更像是轻油而不是 darkolive。)如果您使他调用了一次颜色并存储了该矩阵。

(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.

这篇关于查找接近colorBrewer调色板的颜色的颜色名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆