R将colormap图例和勾选的轴添加到rgl surface3d

时间:2015-05-27 15:55:07

标签: r rgl

我在下面用rgl包支持编写了测试代码。如何在此图中添加色标? 谢谢。

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 个答案:

答案 0 :(得分:2)

实际上,我找到了解决问题的方法。 这是代码:

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