R:rgl 将多个图链接到单个小部件

问题描述

我正在尝试将 playwidget() 滑块链接到多个绘图,以便滑块影响所有绘图。我想在 Rmarkdown 文件中使用它,而不是在 Shiny 应用程序中。

我设法在 subsetControl 中附加了绘图并添加了 subscenes 控件,但它无法正常工作:第一个子集工作正常,但如果我移动滑块,我会得到第一个绘图(带有黑点和红点)在两个图中重复。

library(rgl)

open3d() # Remove the earlier display

layout3d(matrix(c(1,2),nrow=1),sharedMouse = T)

next3d()
setosa <- with(subset(iris,Species == "setosa"),spheres3d(Sepal.Length,Sepal.Width,Petal.Length,col="black",radius = 0.211))
versicolor <- with(subset(iris,Species == "versicolor"),col="red",radius = 0.211))

next3d()
setosa2 <- with(subset(iris,col="yellow",radius = 0.211))
versicolor2 <- with(subset(iris,col="blue",radius = 0.211))


rglwidget() %>%
  playwidget(start = 0,stop = 2,interval = 1,subsetControl(1,subscenes = subsceneList(),subsets = list(
               All = c(setosa,setosa2,versicolor,versicolor2),Setosa = c(setosa,setosa2),Versicolor = c(versicolor,versicolor2)
             )))

解决方法

rgl 子场景中使用的模型是根拥有所有对象,每个子场景显示其中一些。您的代码首先在第一个子场景中显示 setosaversicolor,在第二个子场景中显示 setosa2versicolor2,但是子集控件说要显示 both setosasetosa2 在一个子集中,两者 versicolorversicolor2 在另一个子集中,并在 两者中执行此操作 子场景。由于 setosasetosa2 具有相同的形状和位置,因此一次只出现一个:绘制的第一个。

要得到你想要的东西,你需要两个 subsetControl,都由同一个 playwidget 控制,例如

library(rgl)

open3d() # Remove the earlier display

layout3d(matrix(c(1,2),nrow=1),sharedMouse = T)

next3d()
sub1 <- subsceneInfo()$id
setosa <- with(subset(iris,Species == "setosa"),spheres3d(Sepal.Length,Sepal.Width,Petal.Length,col="black",radius = 0.211))
versicolor <- with(subset(iris,Species == "versicolor"),col="red",radius = 0.211))

next3d()
sub2 <- subsceneInfo()$id
setosa2 <- with(subset(iris,col="yellow",radius = 0.211))
versicolor2 <- with(subset(iris,col="blue",radius = 0.211))


rglwidget() %>%
    playwidget(start = 0,stop = 2,interval = 1,list(subsetControl(1,subscenes = sub1,subsets = list(
                            All = c(setosa,versicolor),Setosa = setosa,Versicolor = versicolor
                         )),subsetControl(1,subscenes = sub2,subsets = list(
                            All = c(setosa2,versicolor2),Setosa = setosa2,Versicolor = versicolor2
                         ))))

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...