2017-01-23 25 views
1

我試圖在rgl圖上繪製多個背景圖(在我的現實世界中,一個用於線和一個用於點),我希望它們處於不同的角落屏幕。看起來rgl的默認行爲是在調用新的圖例時替換舊的圖例。下面的代碼,從rgllegend3d例如修改,說明了這一點:RGL中的多個二維背景圖

library(rgl) 
x <- rnorm(100) 
y <- rnorm(100) 
z <- rnorm(100) 
open3d() 
par3d(windowRect = c(100, 100, 612, 612)) 
plot3d(x, y, z) 
legend3d(x = 0, y = 0, xjust = 0, yjust = 0, legend = c("2D", "3D"), pch = c(1, 16)) 
legend3d(x = 1, y = 0, xjust = 1, yjust = 0, legend = c("2D", "3D"), pch = c(1, 16)) 

我能做些什麼來解決此問題,並得到多個2D圖形出現?

回答

2

legend3d()plot()之後使用legend()作爲背景。所以它不能製作多個傳說。使用bgplot3d()會更好。

open3d() 
par3d(windowRect = c(100, 100, 612, 612)) 

plot3d(x, y, z) 

bgplot3d({ 
    par(mar = c(0, 0, 0, 0)) 
    plot(0, 0, type = "n", xlim = 0:1, ylim = 0:1, xaxs = "i", 
     yaxs = "i", axes = FALSE, bty = "n") 
    legend(x = 0, y = 0, xjust = 0, yjust = 0, legend = c("2D", "3D"), pch = c(1, 16)) 
    legend(x = 1, y = 0, xjust = 1, yjust = 0, legend = c("2D", "3D"), pch = c(1, 16)) 
}) 

enter image description here