r - Find color names for colors close to colorBrewer palette -
i want use r package sna social network analysis. sna colors elements using r color names (text names).
i'd find near matches colorbrewer palette (set3) color names in r.
there aren't many exact matches in 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]
is there way pick color names qualitative palette in r, or map these rcolorbrewer colors existing colors?
see if useful. (it's 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 might have succeeded looking at:
display.brewer.pal(10,"set3")
(although have never see thistle color, , have thought number 7 more of "lightolive" "darkolive".) proably faster response, although seemed acceptable, if made call colors once , stored matrix.
Comments
Post a Comment