如何解决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
子场景中使用的模型是根拥有所有对象,每个子场景显示其中一些。您的代码首先在第一个子场景中显示 setosa
和 versicolor
,在第二个子场景中显示 setosa2
和 versicolor2
,但是子集控件说要显示 both setosa
和 setosa2
在一个子集中,两者 versicolor
和 versicolor2
在另一个子集中,并在 两者中执行此操作 子场景。由于 setosa
和 setosa2
具有相同的形状和位置,因此一次只出现一个:绘制的第一个。
要得到你想要的东西,你需要两个 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
))))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。