【发布时间】:2023-03-19 18:51:01
【问题描述】:
我正在尝试使用 R 中 visreg 包的 visreg2d 函数创建 RGL 图,以包含到通过在 RMarkdown 文件上运行 knitr 创建的 HTML 文档中。
我能够从 rgl 包函数 plot3d 和 spheres3d 获取 RGL 图,但不能从我的 HTML 文档中对 visreg2d(..., plot.type = "rgl") 的调用中获取。
这是一个示例 RMarkdown 文件,由示例 here 构建而成:
---
output:
html_document:
self_contained: no
---
```{r setup, results='asis'}
library(knitr)
library(rsm)
library(visreg)
knit_hooks$set(webgl = hook_webgl)
cat('<script type="text/javascript">', readLines(system.file('WebGL', 'CanvasMatrix.js', package = 'rgl')), '</script>', sep = '\n')
```
This works fine.
```{r testgl, webgl=TRUE}
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x,y)
plot3d(x, y, z, col=rainbow(1000))
```
This one also works.
```{r testgl2, webgl=TRUE}
open3d()
spheres3d(x, y, z, col=rainbow(1000))
```
```{r, webGL = TRUE}
library(rsm)
swiss2.lm <- lm(Fertility ~ Agriculture*Education, data = swiss)
open3d()
visreg2d(swiss2.lm, "Education", "Agriculture", plot.type = "rgl")
```
对plot3d 和spheres3d 的调用有效,但对visreg2d 的调用无效。也就是说,即使在本地我可以看到 RGL 图,它也不会嵌入到我的 HTML 文档中。任何有关如何使其工作的建议将不胜感激。
【问题讨论】: