As every useR knows, the useR! 2010 conference is being held at NIST in Gaithersburg these days. I have just finished my talk on the R package animation this afternoon. Here are my slides and R code for those who are interested:
Download: Slides (1.6M), and R code (3.6K); Note you may need Acrobat Reader to watch the animations inside the slides.Have fun, even if you are a PhD!
chull() which can generate (indices of) the convex hull for a series of points. Now we can use the R package alphahull to compute the α-convex hull. For those who are not familiar with the α-convex hull, the animation below might be a good illustration for the difference between a convex hull and an α-convex hull. Note how the parameter α affects the shape of the hull:
The above animation can be reproduced with the code below (uncomment the lines to create a GIF animation with the animation package):
animation package. I’ve finished writing the initial version of the function sample.ratio() for this package, which will appear in the version 1.1-2 a couple of days later.
As we know, the benefit of ratio estimation is that sampling skewness may be adjusted for, because the estimation of will make use of the information in the relationship of X and Y:
. Here is a demo (we can see the ratio estimate, denoted by the red line, generally performs better than
):
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:
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:
- use
saveMovie()to get a GIF animation (need ImageMagick) ani.start()andani.stop()can produce an HTML page with the animation in itsaveLatex()can embed an animation into a PDF document
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.
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)
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:
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.
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”.




Recent Comments