[R] Animating a persp plot: non-constant scaling?

Elliot Williams ewilliams at ucsd.edu
Sat Oct 20 22:20:30 CEST 2001


Hi all,

I'm making an animation of a rotating persp plot of some data.  It's easy, 
really:  I just plot the persp in a loop over the theta parameter, saving 
each plot, and then chain them together with ImageMagick (as suggested on 
Paul Johnson's R-tips page).

But...  when you run the animation, because each graph is individually 
re-scaled, the image is not the same size in each frame.  That is, when the 
bounding box is facing you (theta=0), the plotted image is bigger than when 
it's at 45 degrees to the front.  

Here's a simple example:

thetas <- seq(0,360,10)
for (i in 1:36){
	png(paste("image", "_", i, ".png", sep = ""))
	persp(outer(seq(0.1,1,.01),seq(0.2,1,.01), beta), theta=thetas[i])
	dev.off()
}

then rename the files (1 -> 01) so that they're in order 
(is there a clever way around doing this from within R?), 
then animate with a command similar (on Linux) to:

(bash)$ convert -delay 10 -loop 5 image*.png animated.gif

Then open it up with something that likes animated gifs (I use a browser).
See how it wobbles?  Any clues?

Thanks.
Elliot.

-- 
Elliot Williams (ewilliams at ucsd.edu)
Economics Department, UC San Diego
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list