[R] using animation with persp

David Winsemius dwinsemius at comcast.net
Thu May 15 00:33:45 CEST 2014


On May 14, 2014, at 1:50 AM, Babak Bastan wrote:

> I would like to generate animating 3D plot. I have a matrix with 416
> columns and 128 rows. a piece of my matrix looks like this:[,1]
> [,2]         [,3]      [,4]      [,5]      [,6]      ....
>     [1,]   NA 0.4118836 0.6411741 0.7286600 0.7622486 0.7523395
>     [2,]   NA 0.3481329 0.6066273 0.6934485 0.7331430 0.7203792
>     [3,]   NA 0.3582897 0.6019357 0.6938022 0.7239531 0.7150477
>     [4,]   NA 0.3122690 0.5613846 0.6721538 0.7017457 0.7006137
>     [5,]   NA 0.3346040 0.5806079 0.6942141 0.7334901 0.7065037
>     [6,]   NA 0.2409363 0.5051088 0.6464730 0.6815346 0.6610605
>     [7,]   NA 0.2474494 0.5106314 0.6335089 0.6811993 0.6641183
>     [8,]   NA 0.1744042 0.4705273 0.6090679 0.6681272 0.6225694
>     [9,]   NA 0.1589965 0.4493954 0.5974459 0.6495768 0.6409229
>    [10,]   NA 0.2435564 0.4966467 0.6375015 0.6866234 0.6687507
> 
>      ...
> 
> I would like to generate something like [this][1] from [here][2] I am using
> this code:
> 
>    saveGIF({
>      for(i in 1:10)
>      {
>        persp(test, theta = 30, phi = 30, expand = 0.5, col = "lightblue")
>      }
>    },
>    movie.name = "test.gif",
>    interval = 0.2,
>    ani.width = 300,
>    ani.height = 300,)

Is that an extraneous comma?

> 
> 
> but what I am seeing with this code is fixed diagram, what should I do to
> solve my problem? by the way if I chng my code to:
> 
>    test<-MatrixY[(1:10),(1:10)]
>    saveGIF({
>      for(i in 1:10)
>      {
>        persp(test[,i], theta = 30, phi = 30, expand = 0.5, col =
> "lightblue")
>      }
>    },
>    movie.name = "test.gif",
>    interval = 0.2,
>    ani.width = 300,
>    ani.height = 300,)
> 
> I am getting this error:
> 
>    Error in seq.default(0, 1, length.out = ncol(z)) :
>      argument 'length.out' must be of length 1

What do you expect from persp() when you only send it a vector rather than a matrix?

> 
> 	[[alternative HTML version deleted]]
> 

None of your links came through because , .... contrary to the Posting Guide .... you did not post in plaintext.

> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list