Merry ChRistmas!

December 23, 2016

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

Christmas day is soon upon us, so here's a greeting made with R:


Each frame is a Voronoi Tesselation: about 1,000 points are chosen across the plane, which each generate a polygon comprising the region closer to it than any other selected point. These process is repeated for three designs (a heart, the word "Merry", and the word "Xmas"), and the Voronoi tiles are colored according to whether the generating point is within the design. In the transitions between the designs, the points migrate from one selected point in one design to a selected counterpoint in the next. The counterpoint is randomly chosen for the "heart" transition (generating a chaotic assembly effect); and a nearby point is chosen for the "Merry" transition (for a much smoother effect).

There's some interesting R-based magic behind how the animation was created as well. The three designs were created in Adobe Illustrator. Getting shapes from Illustrator into R is a surprisingly simple two-line process: you simply import the design using fromJSON, and extract the component representing line segments which can be immediately drawn in R.  The tesselations were drawn using the geom_voronoi_tile() ggplot2 geom in the Github version of the ggforce package, and colored by checking whether the generating point falls inside the design using the in.out function of the mgcv package. The smooth transition of the generating points from one design to the next were calculated using the tweenr package, and the whole thing was animated using the animation package.

For the complete details on how this lovely greeting was created, including the R code, follow the link to creator Thomas Lin Pedersen's blog post below.

Data Imaginist: Data Driven Christmas Card Animation with Voronoi Tiles

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.


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)