2015-05-27 38 views
0

我使用rgl軟件包支持編寫了以下測試代碼。我怎麼能爲這個情節添加一個色階? 謝謝。R將colormap圖例和勾號軸添加到rgl surface3d

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

回答

1

其實,我找到了解決這個問題的方法。 這裏是代碼:

require(rgl); 
require(fields); 

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=1) # height color lookup table 
col <- colorlut[ H-Hlim[1]+1 ] # assign colors to heights for each point 
par3d(windowRect = c(10, 10, 600, 600)) 
Sys.sleep(0.1) 
bgplot3d(suppressWarnings (image.plot(legend.only=TRUE, legend.args=list(text='legend'), zlim=Hlim,col=col)) )#legend 
surface3d(x,y,z,color=col); 
#persp3d(x,y,z,color=col);