Create optical illusions with R

[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I love optical illusions (like this and this and these), not just because they're fun, but also because they give us insights into how the brain processes sensory information. Apparently so does Kohske Takahashi, who conducts research on cognitive psychology and cognitive neuroscience at the University of Tokyo's Research Center for Advanced Science and Technology. He's re-created some classic optical illusions using R, as part of an upcoming workshop on illusions. Here are some of his examples:

The horizontal lines in this grid are all parallel (which you can verify by looking at the R code that generated it):


Though the stripes appear offset diaglonally, these symbols are arranged in perfect horizontal/vertical tiles, and appear to move as you scroll the page:


The small squares here are all exactly the same shade of grey:


That last one, by the way, is a variant of my favorite illusion of all time. In the diagram below, the squares labelled A and B are also the exact same shade of grey: 

Grey_square_optical_illusionEach of Kohske's illusions requires only a few lines of R code, which goes to show that even simple constructs can play havok with how our brain makes sense of visual signals. You can find the R code for these illusions and more (featuring some very elegant uses of the “grid” graphics package), at the document Kohske Takahashi published to RPubs, linked below.

RPubs: Illusions in R / Rで錯視 (via Greg Linch) 

To leave a comment for the author, please follow the link and comment on their blog: Revolutions. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)