2
我試圖在R中使用visreg
軟件包的visreg2d
函數創建一個RGL圖,以包含在通過在RMarkdown文件上運行knitr
創建的HTML文檔中。R:knitr + RGL:與visreg的visreg2d函數有關的問題
我能從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文檔中。任何意見如何得到這個工作將不勝感激。