[R] persp/ scatterplot3d

Petr Pikal petr.pikal at precheza.cz
Wed Jun 28 16:44:16 CEST 2006


Hi,

there was some thread recently about image, contour, persp.
from persp help page

x, y locations of grid lines at which the values in z are measured. 
These must be in **ascending order**. By default, equally spaced 
values from 0 to 1 are used. If x is a list, its components x$x and 
x$y are used for x and y, respectively. 
z a **matrix** containing the values to be plotted (NAs are allowed). 
Note that x can be used instead of z for convenience. 

so generally

persp(ascending.vector.with.nrow.length, 
ascending.vector.with.ncol.length, 
matrix.with.nrows.and.ncols)

or

persp(x.coords, y.coords, matrix.of.z.values)

is the necessary input. Something like geographical grid and value 
for each set of coordinates.

Or you can use interp function from akima package.

HTH
Petr

From: Mark Hempelmann <e.rehak_at_t-online.de> 
Date: Wed 28 Jun 2006 - 22:55:35 EST
Dear WizaRds, 

    I would like to create a 3d-plot with persp(). I sampled 17 
points with xyz-coordinates (real-life example!), representing the 
peaks of the whole plane with "zero coordinates" x=3,y=3,z=3. My 
intention is to show which entries are above or below the "zero" 
level with persp() on a nicely created grid. I also tried 
scatterplot3d(), but, alas, I am unable to tell the function that my 
points represent the peaks of the plane and are either above or below 
"normal" (whatever that means...) Please help me: 

dat<-
matrix(c(1.33,1.00,2.67,4.33,4.00,5.00,0.67,3.33,1.00,3.00,3.00,1.33,1
.67,1.67,1.33,1.67,2.33,1.67,0.67,1.00,1.33,3.33,2.67,1.67,1.67,2.67,2
.00,0.33,0.67,0.33,2.67,3.33,0.67,0.67,1.33,0.00,4.33,3.33,4.67,3.00,4
.00,5.00,4.00,3.67,1.67,3.00,3.67,3.33,1.00,1.33,0.33), ncol=3) 
colnames(dat)<-c("x","y","z") 

x=dat$x; y=dat$y, z=dat$z 
persp(x,y,z) # doesn't work at all, of course, even if I utilize 
outer() 

scatterplot3d(x,y,z) # returns a 3d scatterplot, but not the way I 
would like to see it fit. 

Thank you so much for your help and support! 

mark 

Petr Pikal
petr.pikal at precheza.cz



More information about the R-help mailing list