# 【1.3】R绘制3D图

## 一、交互3D– plot3d(x,y,z)

library(rgl)
with(aa,{
plot3d(F_GC, F_Tm, F_Len, col="red", size=3)
+})

attach(aa)
plot3d(F_GC, F_Tm, F_Len, col="red", size=3)
detach(aa)


## 二、静态3D– scatterplot3d(x,y,z)

1.普通3D静态图

    library(scatterplot3d)
attach(aa)
scatterplot3d(F_Tm,   # x-axis
F_GC, # y-axis
F_Len,  # z-axis
main="3D Scatterplot"
)


2.绘制透视轴

scatterplot3d(F_Tm,   # x-axis
F_GC, # y-axis
F_Len,  # z-axis
main="3D Scatterplot",
pch=16, highlight.3d=TRUE, type="h"
)


3.绘制透视平面

attach(aa)
s3d <- scatterplot3d(F_Len, # x-axis
F_GC, # y-axis
F_Tm, # z-axis
main="3D Scatterplot",
pch=16, highlight.3d=TRUE, type="h",
xlab="GC",
ylab="Len",
zlab="Tm"

)
fit<-lm(F_Tm ~ F_Len + F_GC) # x,y投射到一个虚拟的平面上，平面的高度由Tm来决定
s3d\$plane3d(fit)


## 三、persp

x <- seq(-2,3,0.05)#x在区间[-2,3]之间，取值隔0.05取一个
y <- seq(-1,7,0.05)#y在区间[-1,7]之间,取值隔0.05取一个
f <- function(x,y)#实现函数
{
x^4-2*x^2*y-2*x*y+2*y^2+4.5*x-4*y+4
}
z <- outer(x,y,f)#让x,y在函数f的关系下作外积运算，形成网格，这样才能绘出三维图形
a <- seq(0,100,10)

for (i in a)
{
persp(x,y,z,theta=i,phi=30,expand=0.7,col="blue")#这里让观看的角度每隔一定时间变一次，theta应该是水平方向#的，phi是竖直方向上的角度
Sys.sleep(3)#让R的运行暂停三秒
}


http://www.cnblogs.com/bourneli/p/3917857.html

http://www.statmethods.net/graphs/scatterplot.html

http://www.klshu.com/25.html