[R] overlaying points and lines on a surface3d rgl plot with axes

Vivek Sutradhara viveksutra at gmail.com
Thu Oct 19 16:47:02 CEST 2017


Hi R users and experts,
I am interested in learning more about the use of 3D plots. Specifically, I
want to add points and lines to a surface plot. And get the axes and labels
plotted also. Here is what I have tried with an example data set :

library(rgl)
vol2 <- 2*volcano # Exaggerate the relief
library(reshape)
mvol2 <- melt(vol2)
str(mvol2)
# First, persp and persp3d plots do not succeed
#persp(mvol2$X1,mvol2$X2,vol2,xlab="X2",ylab="X1",zlab="value",axes=TRUE,ticktype="detailed",cex.lab=1)
persp3d(mvol2$X2,mvol2$X1,vol2,axes=TRUE)
# Error - Increasing 'x' and 'y' values expected ??
# Next, tried to get the axes with the plot3d command
plot3d(mvol2$X1,mvol2$X2,mvol2$value,type="n",xlab="x1",ylab="x2",zlab="value")
# then get the surface - why the x,z, y  sequence?
surface3d(mvol2$X1,vol2,mvol2$X2)

I get the following error message for the surface3d command :
Error in rgl.surface(x = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,  :
  Bad dimension for cols

Additionally, I want points and lines plotted. For example, the points
(1,1,200) and (51,2,232).
I don't seem to have succeeded at any single step. I would appreciate any
help that I can get.
Vivek

	[[alternative HTML version deleted]]



More information about the R-help mailing list