Find color names for colors close to colorBrewer palette

后端 未结 1 1467
一整个雨季
一整个雨季 2021-02-14 06:16

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

I\'d like to find near matches from a ColorBrew

1条回答
  •  甜味超标
    2021-02-14 06:43

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

    enter image description here (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.

    0 讨论(0)
提交回复
热议问题