本文介绍了包括与knitr的交互式3D图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 使用 knitr 可以在 rgl c> Rmarkdown 源文件: ```{r setup} library (1000)$ b $< - rnorm(1000)$ b $< - rnorm(1000)> knit_hooks $ set(rgl = hook_rgl)x< + atan2(x,y)``` ```{r,rgl = TRUE} plot3d(x,y,z,col = rainbow(1000) )``` 但是3D图形在html文档中不是交互式的。是否有可能获得交互式3D图形? rgl 包的 writeWebGL()函数创建一个带有交互式3D图形的html文件,有没有办法包括直接与Rmarkdown这个HTML代码?否则如何手动包含这个html代码? Update 24/06/2013 这是一个例子,今天不工作(3D图形不会出现在Chrome浏览器中): Rmd源文件,这是非常基本的: library(rgl) knit_hooks $ set(webgl = hook_webgl)``````{r,webgl = TRUE} M c(0,0,0),c(-1,4,0),c(4,9,0),c(6,3,0)) points3d(M,col ='red')``````{r} sessionInfo()``` 我用RStudioknit按钮在两种情况下使用不同版本的 rgl 和 knitr 包(但这肯定是由于 rgl 包,因为 writeWebGL 函数的输出发生了问题: 使用R-2.15.2的旧版本:源文件和 html渲染。并且由 writeWebGL 生成的 html文件与rgl_0.93.928 。对我来说,它运作良好(3D图中只有4个红点......在我肮脏的屏幕上不容易看到,但我看到它们)。 使用R-2.15.3的最新版本:源文件和 html渲染。并且由 writeWebGL 生成的 html文件与rgl_0.93.935 。对我而言,它不起作用:3D图不可见。我使用的是Windows 7,它不适用于Chrome浏览器,也不适用于Firefox。 编辑28/06/2013 24/06更新引发的问题与 knitr 无关。我已在这篇文章中对其进行了修改: WebGL渲染与rgl 0.93.935 R包 解决方案我 added a新的钩子 hook_webgl()位于 knitr 中,后者已合并到 rgl 中。这里是一个例子: $ $ $ $ b $ library $($) rgl) knit_hooks $ set(webgl = hook_webgl)``` $ b $```{r testgl,webgl = TRUE} x< - sort (1000))y z plot3d(x,y,z,col = rainbow ))``` 请参阅这里有个例子(和 Rmd source )。 Using knitr it is possible to embed a rgl 3D graphics in a html document from a Rmarkdown source file:```{r setup}library(rgl)knit_hooks$set(rgl = hook_rgl)x <- sort(rnorm(1000))y <- rnorm(1000)z <- rnorm(1000) + atan2(x,y)``````{r, rgl=TRUE}plot3d(x, y, z, col=rainbow(1000))```But the 3D graphic is not interactive in the html document. Is it possible to get an interactive 3D graphic ? The writeWebGL() function of the rgl package creates a html file with an interactive 3D graphic, is there a way to include directly this html code with Rmarkdown ? Otherwise how to include this html code manually ?Update 24/06/2013Here is an example that does not work today (the 3D graphic does not appear in Chrome):the Rmd source file, which is very basic:```{r setup}library(rgl)knit_hooks$set(webgl = hook_webgl)``````{r, webgl=TRUE}M <- rbind( c(0,0,0), c(-1,4,0), c(4,9,0), c(6,3,0) ) points3d(M,col='red')``````{r}sessionInfo()```I have knitted this file with the RStudio "knit" button in two situations using different versions of rgl and knitr packages (but this is surely due to the rgl package because the problem occurs with the output of the writeWebGL function) :old versions with R-2.15.2 : source file and html rendering. And the html file generated by writeWebGL with rgl_0.93.928. For me it works well (there are just 4 red points in the 3D plot... not easy to see on my dirty screen but I see them).latest versions with R-2.15.3 : source file and html rendering. And the html file generated by writeWebGL with rgl_0.93.935. For me it doesn't work: the 3D plot is not visible. I use Windows 7 and it doesn't work with Chrome, neither with Firefox.Edit 28/06/2013The problem raised by the 24/06 update has nothing to do with knitr. I have rephrased it in this post: WebGL rendering with rgl 0.93.935 R package 解决方案 I added a new hook hook_webgl() in knitr, which was incorporated into rgl later. Here is an example:```{r setup}library(knitr)library(rgl)knit_hooks$set(webgl = hook_webgl)``````{r testgl, webgl=TRUE}x <- sort(rnorm(1000))y <- rnorm(1000)z <- rnorm(1000) + atan2(x,y)plot3d(x, y, z, col=rainbow(1000))```See an example here (and Rmd source). 这篇关于包括与knitr的交互式3D图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-13 21:24