2016-07-29 7 views

答えて

2

mfrow3d()を使用して複数の「サブシーン」を1つの「シーン」に配置してから、rglwidget()コマンドを使用してhtmlにシーンを表示します。詳細はhereを参照してください。以下はYihui's answerからスクリプトの大きく変更されたバージョンは、次のとおりです。

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

ありがとう、それは完全に動作します。 – Annie

2

別の解決策は、複数のrglwidget()の値を含めることです。これを行うには、htmltools::tagList()に電話をかけてください。 rglの開発バージョンをhttps://r-forge.r-project.org/R/?group_id=234から使用する場合は、rglwidgetパッケージは必要ありません。 Vinceの例を変更すると、

--- 
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) 
``` 
関連する問題