RGL中的多个2D背景图

时间:2017-01-23 17:20:31

标签: r rgl

我正在尝试将多个背景图例放在rgl图上(在我的实际示例中,一个用于行,一个用于点),我希望它们位于屏幕的不同角落。似乎rgl的默认行为是在调用新图例时替换旧图例。从rgl legend3d示例修改的以下代码说明了这一点:

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图形?

1 个答案:

答案 0 :(得分:2)

legend3d()legend()之后使用plot()创建背景。所以它不能制作多个传说。最好使用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