Drawing a 3D scatterplot with plot3D in R

792 views Asked by At

I have the following plot that I want to use with plot3D.

The commands I use are the following:

 library("plot3D");

 N  <- 100

 xs <- runif(N) * 87

 ys <- runif(N) * 61

 zs <- runif(N)*50 + 154

# scatter + surface
 scatter3D(xs, ys, zs, ticktype = "detailed", pch = 16, 
  bty = "f", xlim = c(1, 87), ylim = c(1,61), zlim = c(94, 215))

This basically plots what I want (other than the legend, which I believe I can remove), but not quite in the right format - I want it to be surfacy, and not just a scatter plot. With the regular plot command, it is relatively easy to add a line that connects between the dots, but I am not sure how to do it in this case.

There is a surf parameter for scatter3D(), which I believe could be used to solve that, but I am not sure what help means by "a fitted surface" and how to create the surface manually. I would expect to just have a way of automatically drawing the surface (as a smooth function).

EDIT: By "surfacy" I am referring to a 3D generalization of a smooth line that goes through points in a 2D plot.

EDIT: Here is an example of what I want to do with the same code above.

 par(mfrow = c(1, 1))

# surface = volcano
M <- mesh(1:nrow(volcano), 1:ncol(volcano))

# 100 points above volcano 
N  <- 100

xs <- runif(N) * 87

ys <- runif(N) * 61

zs <- runif(N)*50 + 154

 # scatter + surface
 scatter3D(xs, ys, zs, ticktype = "detailed", pch = 16, 
   bty = "f", xlim = c(1, 87), ylim = c(1,61), zlim = c(94, 215), 
  surf = list(x = M$x, y = M$y, z = volcano,  
          NAcol = "grey", shade = 0.1))

This set of commands also creates a surface (the "mountain" like part). What I am not sure is how to define this surface from a set of points (i.e., how to create the "volcano" matrix). Also, I am not interested in having the scattered dots, only a fixed surface which is determined from a set of scattered points.

0

There are 0 answers