<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/plotting-traditional-colours-of-japan/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://chichacha.netlify.com/2018/11/29/plotting-traditional-colours-of-japan/"> R on Chi's Impe[r]fect Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>

<br>
<br>
</p>
<p>I was curious to know what colours were <a rel="nofollow" href="https://en.wikipedia.org/wiki/Traditional_colors_of_Japan" target="_blank">Traditional Colours of Japan</a>. One of the site I came across showing 465 palettes of Japanese colour is this one. <a rel="nofollow" href="https://www.colordic.org/w/" target="_blank">Japanese Site with 465 palettes of traditional colour</a>. While site displays colour beautifully, to see every colour you need to scroll quite bit, so I wanted to plot them using <a rel="nofollow" href="https://ggplot2.tidyverse.org/" target="_blank">ggplot2</a>.</p>
<p>First, I wanted to figure out if there’s way to plot many different colours at once, but in somewhat organized manner. So to experiment, I’ve randomly generated 3000 colours and decided to plot them in different way. One way I’ve liked is to plot as below. I thought it looks pretty when colours with same hue are sort of clustered together!</p>
<p><img src="https://i1.wp.com/chichacha.netlify.com/post/2018-11-29-plotting-traditional-colours-of-japan_files/figure-html/Colourful_Flower-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<div>
<h2>Get HEX value from the <a rel="nofollow" href="https://www.colordic.org/w/" target="_blank">website</a> using <a rel="nofollow" href="https://cran.r-project.org/web/packages/rvest/" target="_blank">rvest</a></h2>
<p>Below is to get colour values from website, and convert hex value to HSV, so that I can group colours by “hue” value.</p>
<pre><code>library(rvest)
color_w &lt;- read_html(&quot;https://www.colordic.org/w/&quot;)
#color_y &lt;- read_html(&quot;https://www.colordic.org/y/&quot;)
tmp &lt;-color_w %>% html_nodes(&quot;td&quot;)

color_jpn &lt;- tibble(
  hex= tmp %>% html_attr(&quot;style&quot;) %>% str_remove(.,&quot;background-color:&quot;),
  yomi = tmp %>% html_nodes(&quot;span&quot;) %>% html_text(),
  name = tmp %>% html_nodes(&quot;a&quot;) %>% html_text()
)

## clean name name as name includes everything in td...
color_jpn &lt;-color_jpn %>% 
  mutate(name=str_remove(str_remove(name,yomi),hex))

## I couldn't figure out how to do this in one step... Hex to HSV...
## convert Hexvalue to RGB first
color_jpn_df &lt;-color_jpn %>% 
  mutate(rgb_list = map(hex,my_hex2rgb)) %>% unnest(rgb_list)
## Then convert RGB to HSV... 
color_jpn_df &lt;-color_jpn_df %>% 
  mutate(hsv_list = pmap(list(r,g,b),my_rgb2hsv)) %>% unnest(hsv_list)


## Group into Hue Groups - I chose 10 groups.
color_jpn_df &lt;- color_jpn_df %>% 
  mutate(hue_group=factor(cut_width(h,width=1/10, boundary=0),
                          labels=c(&quot;Red/Yellow&quot;,&quot;Yellow&quot;,&quot;Yellow/Green&quot;,&quot;Green&quot;,&quot;Green/Blue&quot;,&quot;Blue&quot;,&quot;Blue/Purple&quot;,&quot;Purple&quot;,&quot;Puple/Red&quot;,&quot;Red&quot;)))</code></pre>
</div>
<div>
<h2>Fun Part! Making the flower with Japanese Traditional Colours</h2>
<pre><code>## golden angle 
g_ang &lt;- pi*(3-sqrt(5))
color_jpn_df &lt;-color_jpn_df %>% 
  group_by(hue_group) %>%
  mutate(t=row_number(v),
         #t=row_number(s),
         x=sqrt(t)*cos(t*g_ang),
         y=sqrt(t)*sin(t*g_ang),
         g_size=n(),
         h_mean=mean(h)) %>% 
  ungroup()
  
color_jpn_df %>%  
  ggplot(aes(x=x,y=y,color=hex)) + 
  geom_point(aes(size=g_size)) + 
  scale_color_identity() +
  theme_void(base_family=&quot;Roboto Condensed&quot;) +
  facet_wrap(~hue_group,ncol=5) +
  coord_fixed() +
  scale_size_continuous(range=c(4,3), guide=&quot;none&quot;) +
  labs(caption=&quot;There's so many different types of orange colours... &quot;,
       title=&quot;465 Japanese Traditional Colours&quot;)</code></pre>
<p><img src="https://i1.wp.com/chichacha.netlify.com/post/2018-11-29-plotting-traditional-colours-of-japan_files/figure-html/floweRit-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>I thought it was interesting that there are lots of orange-ish colour and yellow colours, but not too many green or blue colours. I am now wondering why…</p>
</div>
<div>
<h2>Chinese Characters Used in Traditional Colour Names</h2>
<p>Since each of colours had name, I also was curious if there are some characters that are used more often than other. Colour name was written in two ways in this website. One in <a rel="nofollow" href="https://en.wikipedia.org/wiki/Kanji" target="_blank">Kanji</a> and other in <a rel="nofollow" href="https://en.wikipedia.org/wiki/Hiragana" target="_blank">Hiragana</a>.</p>
<p>I love <a rel="nofollow" href="https://cran.r-project.org/web/packages/wordcloud2/vignettes/wordcloud.html" target="_blank">wordcloud2</a> to visualize the wordcloud, so I can see which characters appears more often the others.</p>
<pre><code>library(wordcloud2)
library(tidytext)

color_jpn_tidy &lt;- color_jpn_df %>% 
  ungroup() %>% select(yomi,name,hex,hue_group,h_mean) %>% 
  mutate(hue_group_hex = hsv(h_mean,0.8,0.8)) %>%
  unnest_tokens(word,name,token=&quot;characters&quot;)

## What characters are often used in colour names?
color_jpn_tidy %>% 
  count(word,sort=T) %>% 
  mutate(n=sqrt(n)) %>%  ## if I don't transform then 色 just gets displayed too big, and I can't see other characters...  So I've used the hack.
  wordcloud2(fontFamily=&quot;Hiragino Sans W6&quot;, ## this gets ignored in website
             minSize=0.1, size=2,
             color=sample(color_jpn_df$hex),  ## just use random colours out of japanese colour palette!
             rotateRatio=0)</code></pre>
<div></div>
<p></p>
<pre><code>color_jpn_tidy %>% count(word,sort=T) %>% head(10)</code></pre>
<pre><code>## # A tibble: 10 x 2
##    word      n
##    </code></pre></div>