I wrote test code below with rgl package support. How could I add a color scale to this plot? Thank you.
require(rgl);
x=1:100;
y=1:100;
z=matrix(sort(abs(rnorm(100*100,50,30) )),100,100)
H <- z
Hlim <- round(range(H[!is.na(H)]))
Hlen <- Hlim[2] - Hlim[1] + 1
colorlut <- terrain.colors(Hlen,alpha=0) # height color lookup table
col <- colorlut[ H-Hlim[1]+1 ] # assign colors to heights for each point
surface3d(x,y,z,color=col);
#persp3d(x,y,z,color=col);