2017-01-11 4 views
0

Gegeben ein R-Code, ich möchte ein 3D-Oberflächendiagramm zeichnen.Zeichnen eines 3D-Plots in R

Der R-Code ist wie folgt:

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]) 

I das 3D-Oberflächendiagramm ziehen möge, wo ‚AAAA‘ wird die 'X'-Achse sein ‚bbbb‘ wird die' y'-Achse und 'cccc' wird die 'z'-Achse sein.

+0

die Basisfunktion für ein 3D-Oberflächendiagramm ist 'persp()'. Siehe die Dokumentation ('? persp') – arvi1000

Antwort

0

Diese Versuchen:

# 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) 

enter image description here

oder einfach:

library(rgl) 
persp3d(x,y,z, col=z) 

enter image description here