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

Uwe Ligges ligges at statistik.uni-dortmund.de
Sun Oct 21 22:00:04 CEST 2001


Elliot Williams wrote:
> 
> 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?),

Yes:
 paste("image", "_", formatC(i, width=2, flag="0"), ".png", sep = "")


> 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?

It "wobbles" because of the "intelligent scaling" that R does.
I think there is no easy solution for your request. What you can try is
to set some graphical parameters, but I am afraid that wouldn't result
in an absolute non-wobbling movie. 
Maybe ggobi or another software like that can do the trick better than
R?

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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