Create optical illusions with R

December 21, 2012

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


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)