Dec 312009

I have to admit that the previous post on Christmas is actually not much fun. Today I received another pResent from Yixuan which is more interesting:

Dec 242009

Life should be fun. I saw a post in R-help list saying Merry Christmas to other useRs, and I followed up by some R code which can produce a naive animation like this:

Here is the code to generate the above Flash animation with shining Christmas:

library(animation)
saveSWF({
    n = length(speed <- runif(angle <- runif(x <- strsplit("MERRY CHRISTMAS",
        "")[[1]], 0, 360), 0, 15))
    for (j in 1:300) {
        angle = angle + speed
        plot.new()
        plot.window(c(1, n), c(0, 1))
        for (i in 1:n) text(i, 0.5, x[i], srt = angle[i], cex = runif(1,
            1, 4), col = sample(colors(), 1))
        text(n, 0, "Yihui @ 2009-12-24 (http://yihui.name)",
            adj = c(1, 0), col = "white", cex = 0.8)
    }
}, interval = 0.04, dev = "pdf", outdir = getwd(), para = list(mar = rep(0,
    4), bg = "black"), width = 8, height = 1)
## in animation package (>=1.1-0), see demo('Xmas')

There are other animation formats in the R package animation:

  1. use saveMovie() to get a GIF animation (need ImageMagick)
  2. ani.start() and ani.stop() can produce an HTML page with the animation in it
  3. saveLatex() can embed an animation into a PDF document
Nov 112009

Since animation 1.0-9, we will be able to create a PDF document with an animation embedded in it; the function is saveLatex(), and its usage is similar to saveMovie() and saveSWF(): you pass an R expression for creating animations to this function, and this expression will be evaluated in the function; the image frames get recorded by a graphics device. In the end, a LaTeX document is written in a directory, and we can get a PDF document by running pdflatex on the document.

In fact, the key point is the LaTeX package named animate, which can be used to insert image frames into a PDF document to generate an animation. The interface of animations created by this package is quite similar to the HTML animation page by the R package animation, moreover, it also uses JavaScript (in PDF) to animate the image frames.

Oct 102009

Today Romain Francois posted an interesting topic in the R-help list, and you can read his blog post for more details: celebrating R commit #50000. 50000 is certainly not a small number; we do owe R core members a big “thank you” for their great efforts in this fantastic statistical language in the 13 years. When I saw Romain’s data, I suddenly remembered a question I asked to one of Prof Ripley’s student a couple of years ago: does Prof Ripley ever sleep? And he answered “No!”. No wonder we can see Prof Ripley so frequently in the R-help/devel mailing list. If you have stayed on R-help list for enough long time, you’ll surely know several facts, e.g. Martin Maechler will arrive in less than 3 minutes if you dare call an R package “library”, and you will get “Ripleyed” if you are not careful enough in posting your R code.

> library(fortunes)
> fortune("Ripleyed")

And the fear of getting Ripleyed on the mailing list also makes me think, read,
and improve before submitting half baked questions to the list.
 -- Eric Kort
 R-help (January 2006)
Jun 122009
Linlin Yan posted a cool (hot?) simulation of burning fire with R in the COS forum yesterday, which was indeed a warm welcome. I’m not sure whether our forum members will be scared by the “fire” under the title “Welcome to COS Forum”. :grin: The fire was mainly created by the function image() with carefully designed rows and columns in heated colors heat.colors(). Here is one of the pictures generated from his code:

Simulation of Burning Fire in R

Simulation of Burning Fire in R

Oct 202008

Yesterday I wrote some R code to simulate the quincunx, which looks like:

It will appear as a function in the R package animation soon.

Jun 132008

The SWF Tools has provided several SWF utilities for the manipulation and creation of Flash files. Today I just wrote a wrapper saveSWF() in the package “animation” to convert image frames to Flash animations. Here is an example for the kNN algorithm:

I’d like to thank Hadley for telling me this tool set. The function saveSWF() is to appear in animation 1.0-1.

Till now, there are four kinds of animations in the animation package: (1) animations inside R windows graphics devices; (2) animations in HTML pages (driven by JavaScript); (3) GIF or AVI animations with the help of “ImageMagic”; (4) Flash animations with the help of “SWF Tools”.

Jun 042008

I have spent three days on these two plugins. The first one “animation” is written by myself after a quick view of the instructions on writing plugins for Dokuwiki, as there is no such kind of plugins so far. What I want to say is “Regular expression is really a devil”! It has almost taken me a whole day to understand how to use a correct pattern to match the parameters in the tags…

Then I modified the “math” plugin so that it is much easier and more familiar for us to type LaTeX formulae in the wiki pages: just use $...$ or $$...$$. People who are familiar with LaTeX surely know what they mean.

By the way, Philippe Grosjean has kindly provided me the necessary files for highlighting R code in the Dokuwiki system. That’s really fantastic! See this page for some examples.

So the main infrastructure has been built till now; the next step is to modify my animation package and include more functions which have been in my mind for a long time. Then I will begin to migrate the old web pages in http://R.yihui.name to AniWiki.

May 312008

I have finished the TOEFL test today and ultimately I can spend enough time on the animation wiki now:

http://animation.yihui.name

This idea came to my mind the other day; maybe it is quite natural, because what I plan to do is a gallery instead of a limited number of animations. Thus I must choose a way that can interact with other people. The most ideal case, in my mind, would just be a wiki, in which there can be a large amount of different ideas and feedbacks, meanwhile, as I said in the message page, “Many hands make light work”. I really wish people who are interested in animations can create this wiki together with me.

In the next few days, I’ll have to rewrite the JavaScript code in HTML animation pages so that it can be more flexible to be used elsewhere. Besides, the animation functions to create HTML pages will also be revised.

By the way, the old website http://R.yihui.name is to be abandoned as there is too much inconvenience to maintain!

Apr 262008

On April 22 I have given a presentation at the conference MEIDE2 on the topic of “Population Qualities in Innovation“. In my paper I just adopted the technique of “Classification and Regression Tree” (CART) to explore the relationship between the innovation output (measured by the average number of patents in a region) and several kinds of population qualities. In order to explain how CART works on data, I made two animated pictures for the audience:

Regression tree: split by the variable 'mobility rate'

Regression tree: split by the variable 'proportion of urban people'

WWW.YIHUI.NAME XIE@YIHUI.NAME © 2007 - 2010 by Yihui Xie