<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/using-gganimate-to-illustrate-the-luminance-illusion/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2018/08/luminance-illusion.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>Many illusions are based on the fact that our perceptions of color or brightness of an object are highly dependent on the background surrounding the object. For example, in this image (an example of the <a rel="nofollow" href="http://blog.revolutionanalytics.com/2014/01/friday-cornsweet-illusion.html" target="_blank">Cornsweet illusion</a>) the upper and lower blocks are exactly the same color, according to the pixels displayed on your screen.</p>
<blockquote class="twitter-tweet" data-lang="en">
<p dir="ltr" lang="en">Mind = blown. These two blocks are exactly the same shade of grey. Hold your finger over the seam and check. <a rel="nofollow" href="http://t.co/OqAnforGqs" target="_blank">pic.twitter.com/OqAnforGqs</a></p>
<p>â€&quot; David Smith (@revodavid) <a rel="nofollow" href="https://twitter.com/revodavid/status/408696030956244993?ref_src=twsrc%5Etfw" target="_blank">December 5, 2013</a></p></blockquote>
<p></p>
<p>Here's another simpler representation of the principle, <a rel="nofollow" href="https://rtask.thinkr.fr/blog/luminance-gradient-dependent-lightness-illusion/" target="_blank">created by Colin Fay</a> (in response to <a rel="nofollow" href="https://twitter.com/AkiyoshiKitaoka/status/1028473566193315841" target="_blank">this video</a> made with <a rel="nofollow" href="http://www.psy.ritsumei.ac.jp/~akitaoka/kosaku2e.html" target="_blank">colored paper</a>). In the animation below, the rectangle moving to the left to right remains the same color throughout (a middling gray). But as the background around it changes, our perception of the color changes as well.</p>
<p><a rel="nofollow" href="https://rtask.thinkr.fr/blog/luminance-gradient-dependent-lightness-illusion/" target="_blank"><img border="0" alt="Lightness_illusion" title="Lightness_illusion" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b022ad38b4cbe200d-800wi"></a></p>
<p>Colin created this animation in R using the <a rel="nofollow" href="https://github.com/thomasp85/gganimate" target="_blank">gganimate package</a> (available on GitHub from author Thomas Lin Pederson), and the process is delightfully simple. It begins with a chart of 10 &quot;points&quot;, each being the same grey square equally spaced across the shaded background. Then, a simple command animates the transitions from one point to the next, and interpolates between them smoothly:</p>
<pre>library(gganimate)
gg_animated &lt;- gg + 
  transition_time(t) + 
  ease_aes('linear')
</pre>
<p>You can find the complete R source code behind the animation at the blog post linked below, along with an interesting discussion of luminance and how you should consider it when choosing color scales for your data visualizations.</p>
<p>RTask: <a rel="nofollow" href="https://rtask.thinkr.fr/blog/luminance-gradient-dependent-lightness-illusion/" target="_blank">Remaking â€˜Luminance-gradient-dependent lightness illusionâ€<img alt="™" src="https://s.w.org/images/core/emoji/11/72x72/2122.png" class="wp-smiley"> with R</a></p>
</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="http://blog.revolutionanalytics.com/2018/08/luminance-illusion.html"> Revolutions</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/e6R4Wi_5PWg" height="1"></a></div>