我正在循环中使用plot3d {rgl}绘制3d图形。knitr rgl挂钩对于单个3d图形效果很好,但是在循环中使用时,markdown文件不包含3d图形。
一种方法是,mfrow3d()
将多个“子场景”放在单个“场景”中,然后使用rglwidget()
命令在html中显示场景。在此处查看更多信息。以下是Yihui的答案的脚本的大量修改版本:
---
output: html_document
---
You will need to install the rglwidget library if you have not already.
```{r setup}
library(knitr)
library(rgl)
library(rglwidget)
```
Using mfrow3d() I create a scene with 5 subscenes,
so each of the 5 plots will appear in a single scene.
Each will still be independently interactive (can zoom in on one at a time, e.g.).
```{r testgl}
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x,y)
mfrow3d(nr = 5, nc = 1)
cols <- c("red", "orange", "green", "blue", "purple")
for(i in 1:5){
plot3d(x, y, z, col = cols[i])
}
rglwidget(height = 4000, width = 1000)
```
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句