我正在循环中使用plot3d {rgl}绘制3d图形。include hooks适用于单个3d图形,但当在循环中使用时,markdown文件不包括3d图形。
发布于 2016-07-30 03:29:13
一种方法是使用mfrow3d()在单个“场景”中放置多个“子场景”,然后使用rglwidget()命令在html中显示场景。请参阅更多信息here。下面是来自Yihui's answer的经过大量修改的脚本版本
---
output: html_document
---
You will need to install the rglwidget library if you have not already.
```{r setup}库(Knitr)
库(Rgl)
库(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 <-排序(rnorm(1000))
Y <- rnorm(1000)
Z <- rnorm(1000) + atan2(x,y)
mfrow3d(nr = 5,nc = 1)
cols <- c(“红色”,“橙色”,“绿色”,“蓝色”,“紫色”)
对于(1:5中的i){
plot3d(x, y, z, col = cols[i])}
rglwidget(高度= 4000,宽度= 1000)
发布于 2016-08-04 19:43:57
另一种解决方案是包含多个rglwidget()值。您需要将它们都放在一个对htmltools::tagList()的调用中,这样才能正常工作。(如果使用来自https://r-forge.r-project.org/R/?group_id=234的rgl开发版本,则不需要rglwidget包)。修改文斯的例子,
---
output: html_document
---
```{r setup}库(Rgl)
库(Rglwidget)
```{r testgl}X <-排序(rnorm(1000))
Y <- rnorm(1000)
Z <- rnorm(1000) + atan2(x,y)
cols <- c(“红色”,“橙色”,“绿色”,“蓝色”,“紫色”)
result <- list()
对于(1:5中的i){
plot3d(x, y, z, col = cols[i])result[[i]] <- rglwidget()}
htmltools::tagList(结果)
https://stackoverflow.com/questions/38664432
复制相似问题