The xkcdcolors package (on CRAN) wraps the nearly 1000 most reliably named colours from the XKCD colour survey, based on about \(2.2\times 10^5\) participants.

A function I didn’t think of until after I’d submitted the package to CRAN, this rounds a supplied colour name to the closest match among the \(2^\mathrm{bits}\) most popular colours.

library("xkcdcolors")
round_color<-function(color, bits=5, Lab=TRUE, hex_only=TRUE){
  nearest_named(name2color(color),hex_only=hex_only,
    max_rank=2^bits,Lab=Lab)
}

Here’s what the entire color database looks like under progressive rounding from the full 10 bits down to 0.

rounded<-lapply(10:0, function(i) round_color(xcolors(),bits=i))
plot(1,1,ylim=c(0,10),xlim=c(1,949),type="n",axes=F,xlab="",ylab="bits")
index<-do.call(order,rev(rounded))
for(i in 1:11) segments(x0=1:949,y0=i-1,y1=i,col=rounded[[i]][index])

This isn’t a hierarchical clustering: two colours can have the same closest approximation to 3 bits but different closest approximations to 2 bits. It still comes pretty close. Here’s the top of the not-quite-a-tree:

xcolors(2^0)
## [1] "purple"
xcolors(2^1)
## [1] "purple" "green"
xcolors(2^2)
## [1] "purple" "green"  "blue"   "pink"
xcolors(2^3)
## [1] "purple"     "green"      "blue"       "pink"       "brown"     
## [6] "red"        "light blue" "teal"
xcolors(2^4)
##  [1] "purple"       "green"        "blue"         "pink"        
##  [5] "brown"        "red"          "light blue"   "teal"        
##  [9] "orange"       "light green"  "magenta"      "yellow"      
## [13] "sky blue"     "grey"         "lime green"   "light purple"