【问题标题】:How to pick an element using mouse in RGL plot3d?如何在 RGL plot3d 中使用鼠标选择元素?
【发布时间】:2017-04-03 22:46:08
【问题描述】:

我计算我的多元数据集的主成分,并将前 3 个主成分的分数显示为带有rgl::plot3d 的 3 维交互图上的球体。不幸的是,并不总是清楚 3D 图上的哪个球体对应于我的数据集中的哪个观察值。 是否有一些简单的方法可以添加鼠标回调来返回被点击球体的索引?

# For example, I plot iris
library(rgl)
with(iris, plot3d(Sepal.Length, Sepal.Width, Petal.Length, 
                      type="s", col=as.numeric(Species)))

# Now I click on some data points and want to get their indices
# how?

我检查了WebGL user interaction tutorial,但它没有提到这样的功能。我还发现,通过 translationMatrixrgl.setMouseCallbacks 的精美组合,可以在绘图坐标中获取鼠标指针的位置,然后可能链接到最近的元素,但这似乎非常复杂。

【问题讨论】:

  • plotly可以看一下:plot.ly/r/3d-scatter-plots
  • 谢谢,这很好。 plotly 的能力看起来真的很厉害,我试试看。
  • plot.ly 3d 据我所知,在 rgl 的 flexibilite 附近没有任何地方。很遗憾。它甚至没有办法做线段。

标签: r rgl


【解决方案1】:

好吧,在问题Have names on the spheres built by rgl package plot3d 中我找到了一个answer,而不是提到函数rgl::identify3d。它完全符合我的要求。这是一个最小的工作示例:

library(rgl)
attach(iris)
plot3d(Sepal.Length, Sepal.Width, Petal.Length, 
       type="s", col=as.numeric(Species))
pts <- identify3d(Sepal.Length, Sepal.Width, Petal.Length,
       labels = rownames(iris))
# Use the right button to select, the middle button to quit

pts
# [1] 120 107  42  14   2 106 118
detach(iris)

iris[pts, ]  # get selected observations

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多