鉴于R代码,我想绘制一个3D表面图。
R代码如下:
x=seq(1,5,1)
y=seq(6,10,1)
m=as.matrix(expand.grid(x,y))
a=m[,1]+m[,2]
mm=cbind(m,a)
mm1=data.frame(aaaa=mm[,1],bbbb=mm[,2],cccc=mm[,3])
我想绘制3D曲面图,其中'aaaa'将是'x'轴,'bbbb'将是'y'轴,'cccc'将是'z'轴。
答案 0 :(得分:0)
试试这个:
# surface plot
x=seq(1,5,1)
y=seq(6,10,1)
z <- outer(x, y)
nrz <- nrow(z)
ncz <- ncol(z)
jet.colors <- colorRampPalette( c("blue", "green") )
nbcol <- length(a)
color <- jet.colors(nbcol)
zfacet <- z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz]
facetcol <- cut(zfacet, nbcol)
persp(x, y, z, col = color[facetcol], phi = 30, theta = -30)
或者只是这个:
library(rgl)
persp3d(x,y,z, col=z)