A Rookie of R.






  1. Color hunt
  2. nipponcolor
  3. ColorBrewer
  4. 中国传统色彩



Recently, I was amazed by the fantastic art of data visualization created by Namier and Shirley. Namier showed her working process of Cardcaptor Sakura, and I read the passages as below :

Using the imager package in R, I loaded the images into R where each pixel was transformed into a multidimensional array of RGBA values. I converted that complex array into a more simple data frame of (number of pixels) * 3 (for r, g, and b value) size. To figure out which algorithm would cluster the pixel values into decent colors groups I tried several things. First I experimented with using different clustering techniques: from the standard K-means, to hierarchical clustering and even tSNE. But I also converted the RGB values of each pixel into other color spaces (where colors have different “distances” to each other and can thus result into different clustering results), using, amongst others, the colorspace package.
I often converted the results of each test into a bar chart such as below to see the color groups found. Eventually, I found that using Kmeans together with the colors converted to “Lab” visually gave the best fitting results.

I thought though I am not famliar with D3.js (so hard, but I want to acknowledge it one day, as it is so coooool!), I have a basis of using R. So, I want to try those two packages, ‘imager’ and ‘colorspace’, to select main colors from a targeted picture, and maybe draw a bar chart like Nadieh had done.