繁体   English   中英

如何在循环下的markdown(knitr)中包含多个plot3d

[英]How to include multiple plot3d in markdown (knitr) under a loop

我正在循环中使用plot3d {rgl}绘制一个三维图形。 knitr rgl hooks适用于单个3d图形,但在循环中使用时,markdown文件不包含3d图形。

你可以做的一种方法是使用mfrow3d()将多个“subscenes”放在一个“场景”中,然后使用rglwidget()命令在你的html中显示场景。 在此处查看更多信息。 以下是易辉答案的剧本修改版:

---
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)
```

另一种解决方案是包含多个rglwidget()值。 你需要将它们全部放在对htmltools::tagList()的调用中才能htmltools::tagList()工作。 (如果您使用来自https://r-forge.r-project.org/R/?group_id=234rgl的开发版本,则不需要rglwidget包)。 修改文斯的例子,

---
output: html_document
---

```{r setup}
library(rgl)
library(rglwidget)
```

```{r testgl}
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x,y)

cols <- c("red", "orange", "green", "blue", "purple")
result <- list()
for(i in 1:5){
    plot3d(x, y, z, col = cols[i])
    result[[i]] <- rglwidget()
}
htmltools::tagList(result)
```

暂无
暂无

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

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