【发布时间】:2020-08-26 10:36:21
【问题描述】:
如何将 3D 绘图 (rgl) 嵌入到通过 knitr 创建的 html 中?
有几篇较早的帖子正在寻找类似的结果。但是,当我运行我找到的所有示例代码时。 rgl-plot 不会嵌入到使用 knitr 创建的 html 中,而是在“编织”时出现在外部窗口中,并在 html 页面出现时消失。
我正在寻找一种将 3D 绘图集成到生成的 html 中的方法。我不介意它是保持交互还是变成静态。
以下示例取自 R Markdown Cookbook:https://bookdown.org/yihui/rmarkdown-cookbook/rgl-3d.html
title: Embed 3D plots with rgl
output: html_document
---
Set up a hook to save **rgl** plots:
```{r, setup}
library(rgl)
knitr::knit_hooks$set(webgl = hook_webgl)
```
See if it works for this 3D plot after we enable the hook
via the chunk option `webgl = TRUE`:
```{r, test-rgl, webgl=TRUE}
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x,y)
plot3d(x, y, z, col = rainbow(1000))
```
【问题讨论】:
标签: r-markdown knitr rgl