简体   繁体   English

切换按钮来控制 rgl 3d 散点图不起作用

[英]toggle buttons to control rgl 3d scatterplot not working

We are working on a meta analysis about lizard niches and convergent evolution, and created a 3d plot with PCA scores, were dots are lizard species from 24 different families.我们正在对蜥蜴生态位和趋同进化进行元分析,并创建了一个带有 PCA 分数的 3d 图,点是来自 24 个不同科的蜥蜴物种。 We decided to use our 3d plots as supplementary material for our manuscript because there are very interesting patterns that are obscured when plotted in 2 dimensions.我们决定使用我们的 3d 绘图作为我们手稿的补充材料,因为在 2 维绘图时,有一些非常有趣的图案会被掩盖。 For example, all nocturnal species stick together, and are separated from the rest in the third plane.例如,所有夜间活动的物种都粘在一起,并在第三个平面中与其他物种分开。

So, to make the figures really useful, I wanted to include some controls to turn some objects on/off (like lizard families, or ellipsoids, or functional groups).因此,为了使图形真正有用,我想包含一些控件来打开/关闭某些对象(如蜥蜴家族、椭圆体或功能组)。 I tried using Plotly, that gives you very nice and interactive plots, but symbols in Plotly are limited to only five for 3D plots.我尝试使用 Plotly,它可以为您提供非常漂亮的交互式绘图,但 Plotly 中的符号仅限于 5 个用于 3D 绘图。

I finally did it with R using the rgl package.我终于使用 rgl 包用 R 做到了。 I had to create new symbols by overlapping pre-existent ones, but and at the end I got what I needed.我不得不通过重叠先前存在的符号来创建新符号,但最后我得到了我需要的东西。

I followed an online tutorial to create interactive controls ( https://cran.r-project.org/web/packages/rgl/vignettes/WebGL.html ) that can be embedded in html, and with a lot of effort I got those controls working.我按照在线教程创建了可以嵌入到 html 中的交互式控件( https://cran.r-project.org/web/packages/rgl/vignettes/WebGL.html ),经过很多努力,我得到了这些控制工作。 The problem is that it only works in my computer, only in Chrome (does not work in Firefox, nor Safari).问题是它只适用于我的电脑,只适用于 Chrome(不适用于 Firefox,也不适用于 Safari)。 I asked one of the creators of the package and he told me that the tutorial was intended to be use with markdown, and given I changed the html code, the weird behavior was not surprising.我询问了该软件包的一位创建者,他告诉我该教程旨在与 Markdown 一起使用,并且鉴于我更改了 html 代码,这种奇怪的行为并不奇怪。

After that I learn some Rmarkdown and html to better understand the tutorial, and re-do the code.之后我学习了一些Rmarkdown和html以更好地理解教程,并重新编写代码。 Now I have the plots and I have the buttons, but when I compile the script using Knitr, the buttons don't work.现在我有了绘图和按钮,但是当我使用 Knitr 编译脚本时,按钮不起作用。 Some of them do nothing, some others turn on different set of points.他们中的一些人什么都不做,另一些人打开不同的点集。

I am sorry for the length of this post, but I really tried everything and I can't find a solution.我很抱歉这篇文章的长度,但我真的尝试了一切,但找不到解决方案。

Here is a link to a sample of my dataset, my R script, and the HTML generated using Knitr: https://drive.google.com/open?id=0B-fCxMGN3utrbWgtZzhWYVpxSjg这是我的数据集示例、我的 R 脚本和使用 Knitr 生成的 HTML 的链接: https ://drive.google.com/open ? id = 0B-fCxMGN3utrbWgtZzhWYVpxSjg

Thank you so much in advance!非常感谢您!

The issue is that there are at least two different schemes for embedding rgl scenes in a web page and for linking a button to the rgl scene, and you're mixing them without providing the "glue" to make them work together.问题是至少有两种不同的方案用于在网页中嵌入 rgl 场景以及将按钮链接到 rgl 场景,并且您在不提供“胶水”的情况下混合它们以使它们一起工作。

An rglwidget() always has an elementId .一个rglwidget()总是有一个elementId Normally it's some random string, but if you want to refer to that scene, you should specify one.通常它是一些随机字符串,但如果你想引用那个场景,你应该指定一个。

The toggleButton() function uses the older scheme for inserting the scene into your web page. toggleButton()函数使用旧方案将场景插入到您的网页中。 So you need to translate the elementId to the prefix that it uses.因此,您需要将elementId转换为它使用的前缀。

So try something like this:所以尝试这样的事情:

```{r results='asis'}
library(rgl)
x <- plot3d(rnorm(10), rnorm(10), rnorm(10))
rglwidget(elementId = "theplot")
elementId2Prefix("theplot")
toggleButton(x["data"], prefix = "theplot")
```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM