<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/scico-and-the-colour-conundrum/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.data-imaginist.com/2018/scico-and-the-colour-conundrum/"> Data Imaginist</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img align="right" src="https://i0.wp.com/www.data-imaginist.com/assets/images/scico_logo_small.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>I’m happy to once again announce the release of a package. This time it happens to be a rather unplanned and quick new package, which is fun for a change. The package in question is <code>scico</code> which provides access to the <a rel="nofollow" href="http://www.fabiocrameri.ch/colourmaps.php" target="_blank">colour palettes developed by Fabio Crameri</a> as well as scale functions for <code>ggplot2</code> so they can be used there. As there is not a lot to talk about in such a simple package I’ll also spend some time discussing why choice of colour is important beyond aesthtic considerations, and discuss how the quality of a palette might be assesed.</p>
<div>
<h2>An overview of the package</h2>
<p><code>scico</code> provides a total of 17 different continuous palettes, all of which are available with the <code>scico()</code> function. For anyone having used <code>viridis()</code> the <code>scico()</code> API is very familiar:</p>
<pre><code>library(scico)
scico(15, palette = 'oslo')</code></pre>
<pre><code>##  [1] &quot;#000000&quot; &quot;#09131E&quot; &quot;#0C2236&quot; &quot;#133352&quot; &quot;#19456F&quot; &quot;#24588E&quot; &quot;#3569AC&quot;
##  [8] &quot;#4D7CC6&quot; &quot;#668CCB&quot; &quot;#7C99CA&quot; &quot;#94A8C9&quot; &quot;#ABB6C7&quot; &quot;#C4C7CC&quot; &quot;#E1E1E1&quot;
## [15] &quot;#FFFFFF&quot;</code></pre>
<p>In order to get a quick overview of all the available palettes use the <code>scico_palette_show()</code> function:</p>
<pre><code>scico_palette_show()</code></pre>
<p><img src="https://i2.wp.com/www.data-imaginist.com/post/2018-05-30-scico-and-the-colour-conundrum_files/figure-html/unnamed-chunk-2-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>As can be seen, the collection consists of both sequential and diverging palettes, both of which have their own uses depending on the data you want to show. A special mention goes to the <code>oleron</code> palette which is intended for topographical height data in order to produce the well known <em>atlas look</em>. Be sure to center this palette around 0 or else you will end up with very misleading maps.</p>
<p><code>ggplot2</code> support is provided with the <code>scale_[colour|color|fill]_scico()</code> functions, which works as expected:</p>
<pre><code>library(ggplot2)
volcano &lt;- data.frame(
  x = rep(seq_len(ncol(volcano)), each = nrow(volcano)),
  y = rep(seq_len(nrow(volcano)), ncol(volcano)),
  Altitude = as.vector(volcano)
)

ggplot(volcano, aes(x = x, y = y, fill = Altitude)) + 
  geom_raster() + 
  theme_void() +
  scale_fill_scico(palette = 'turku') </code></pre>
<p><img src="https://i2.wp.com/www.data-imaginist.com/post/2018-05-30-scico-and-the-colour-conundrum_files/figure-html/unnamed-chunk-3-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>This is more or less all there is for this package… Now, let’s get to the meat of the discussion.</p>
</div>
<div>
<h2>What’s in a colour?</h2>
<p>If you’ve ever wondered why we are not all just using rainbow colours in our plots (after all, rainbows <em>are</em> pretty…) it’s because our choice of colour scale have a deep impact on what changes in the underlying data our eyes can percieve. The rainbow colour scale is still very common and notoriously bad – see e.g. <a rel="nofollow" href="https://ieeexplore.ieee.org/document/4118486/" target="_blank">Borland &amp; Taylor (2007)</a>, <a rel="nofollow" href="https://blogs.egu.eu/divisions/gd/2017/08/23/the-rainbow-colour-map/" target="_blank"><em>The Rainbow Colour Map (repeatedly) considered harmful</em></a>, and <a rel="nofollow" href="https://eagereyes.org/basics/rainbow-color-map" target="_blank"><em>How The Rainbow Color Map Misleads</em></a> – due to two huge problems that are fundamental to designing good colour scales: <em>Perceptual Uniformity</em> and <em>Colour Blind Safe</em>. Both of these issues have been taken into account when designing the <code>scico</code> palettes, but let’s tackle them one by one:</p>
<div>
<h3>Colour blindness</h3>
<p>Up to 10% of north european males have the most common type of colour blindness (deuteranomaly, also known as red-green colour blindness), while the number is lower for other population groups. In addition, other, rarer, types of colour blindness exists as well. In any case, the chance that a person with a color vision deficiency will look at your plots is pretty high.</p>
<p>As we have to assume that the plots we produce will be looked at by people with color vision deficiency, we must make sure that the colours we use to encode data can be clearly read by them (ornamental colours are less important as they – hopefully – don’t impact the conclusion of the graphic). Thanksfully there are ways to simulate how colours are percieved by people with various types of colour blindness. Let’s look at the rainbow colour map:</p>
<pre><code>library(pals)

pal.safe(rainbow, main = 'Rainbow scale')</code></pre>
<p><img src="https://i0.wp.com/www.data-imaginist.com/post/2018-05-30-scico-and-the-colour-conundrum_files/figure-html/unnamed-chunk-4-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>As can be seen, there are huge areas of the scale where key tints disappears, making it impossible to correctly map colours back to their original data values. Put this in contrast to one of the <code>scico</code> palettes:</p>
<pre><code>pal.safe(scico(100, palette = 'tokyo'), main = 'Tokyo scale')</code></pre>
<p><img src="https://i2.wp.com/www.data-imaginist.com/post/2018-05-30-scico-and-the-colour-conundrum_files/figure-html/unnamed-chunk-5-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>While colour blindness certainly have an effect here, it is less detrimental as changes along the scale can still be percieved and the same tint is not occuring at multiple places.</p>
</div>
<div>
<h3>Perceptual uniformity</h3>
<p>While lack of colour blind safety “only” affects a subgroup of your audience, lack of perceptual uniformity affects everyone – even you. Behind the slightly highbrow name lies the criteria that equal jumps in the underlying data should result in equal jumps in percieved colour difference. Said in another way, every step along the palette should be percieved as giving the same amount of difference in colour.</p>
<p>One way to assess perceptual uniformity is by looking at small oscillations inside the scale. Let’s return to our favourite worst rainbow scale:</p>
<pre><code>pal.sineramp(rainbow, main = 'Rainbow scale')</code></pre>
<p><img src="https://i2.wp.com/www.data-imaginist.com/post/2018-05-30-scico-and-the-colour-conundrum_files/figure-html/unnamed-chunk-6-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>We can see that there are huge differences in how clearly the oscilations appear along the scale and around the green area they even disappears. In comparison the <code>scico</code> palettes produces much more even resuls:</p>
<pre><code>pal.sineramp(scico(100, palette = 'tokyo'), main = 'Tokyo scale')</code></pre>
<p><img src="https://i1.wp.com/www.data-imaginist.com/post/2018-05-30-scico-and-the-colour-conundrum_files/figure-html/unnamed-chunk-7-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
</div>
<div>
<h3>But wait – there’s more!</h3>
<p>This is just a very short overview into the world of colour perception and how it affects information visualisation. The <code>pals</code> package contains more functions to assess the quality of colour palettes, some of which has been collected in an ensemble function:</p>
<pre><code>pal.test(scico(100, palette = 'broc'), main = 'Broc scale')</code></pre>
<p><img src="https://i1.wp.com/www.data-imaginist.com/post/2018-05-30-scico-and-the-colour-conundrum_files/figure-html/unnamed-chunk-8-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>It also has <a rel="nofollow" href="https://cran.r-project.org/web/packages/pals/vignettes/pals_examples.html" target="_blank">a vignette</a> that explains in more detail how the different plots can be used to look into different aspects of the palette.</p>
<p><code>scico</code> is also not the only package that provides well-designed, safe, colour palettes. <a rel="nofollow" href="https://cran.r-project.org/web/packages/RColorBrewer/index.html" target="_blank"><code>RColorBrewer</code></a> has been a beloved utility for a long time, as well as the more recent <a rel="nofollow" href="https://cran.r-project.org/web/packages/viridis/index.html" target="_blank"><code>viridis</code></a>. Still, choice is good and using the same palettes for prolonged time can make them seem old and boring, so the more the merrier.</p>
<p>A last honerable mention is <a rel="nofollow" href="https://github.com/EmilHvitfeldt/r-color-palettes/blob/master/README.md" target="_blank">the overview of palettes in R</a> that <a rel="nofollow" href="https://twitter.com/Emil_Hvitfeldt" target="_blank">Emil Hvitfeldt</a> has put together. Not all of the palettes in it (the lions share actually) have been designed with the issues discussed above in mind, but sometimes thats OK – at least you now know how to assess the impact of your choice and weigh it out with the other considerations you have.</p>
<p><em>Always be weary of colours</em></p>
</div>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.data-imaginist.com/2018/scico-and-the-colour-conundrum/"> Data Imaginist</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/BnS-9Lxs5-o" height="1"></a></div>