用R绘制交互式3D图

1. 安装rgl包、evd包和MASS包:

 

> install.packages("rgl")
Installing package(s) into ‘D:/program/R/library’
(as ‘lib’ is unspecified)
试开URL’http://cran.dataguru.cn/bin/windows/contrib/2.15/rgl_0.92.892.zip'
Content type 'application/zip' length 1937097 bytes (1.8 Mb)
打开了URL
downloaded 1.8 Mb

package ‘rgl’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\LiQiang\AppData\Local\Temp\RtmpIjwxP2\downloaded_packages
> install.packages("evd")
Installing package(s) into ‘D:/program/R/library’
(as ‘lib’ is unspecified)
试开URL’http://cran.dataguru.cn/bin/windows/contrib/2.15/evd_2.3-0.zip'
Content type 'application/zip' length 1176009 bytes (1.1 Mb)
打开了URL
downloaded 1.1 Mb

package ‘evd’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
  C:\Users\LiQiang\AppData\Local\Temp\RtmpIjwxP2\downloaded_packages
> install.packages("MASS")
Installing package(s) into ‘D:/program/R/library’
(as ‘lib’ is unspecified)
试开URL’http://cran.dataguru.cn/bin/windows/contrib/2.15/MASS_7.3-21.zip'
Content type 'application/zip' length 872270 bytes (851 Kb)
打开了URL
downloaded 851 Kb

package ‘MASS’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\LiQiang\AppData\Local\Temp\RtmpIjwxP2\downloaded_packages

 

 

2. 输入程序

library(rgl)
library(MASS)
library(evd);
data(lossalae)
U=rand(lossalae[,1]+rnorm(nrow(lossalae),mean=0,sd=.001))/(nrow(lossalae)+1)
V=rank(lossalae[,2])/(nrow(lossalae)+1)
M=kde2d(qnorm(U), qnorm(V), n=35)
persp3d(M$x, M$y, M$z, col='green',xlab="loss", ylab="alae", zlab="")

 

3. 输出3D


 

 

 

posted on 2012-09-24 22:57  YangJin  阅读(422)  评论(0编辑  收藏  举报