Rottation of R 3d plots not working properly with knitr and webgl

假如想象 提交于 2019-12-01 22:20:42

问题


I am trying to use rgl knitr and webgl to plot several interactive 3d plots in a sequence.

And I am getting quite a weird behavior: when trying to rotate the plots with a mouse they seem to get back to their initial position after each mouse drag. This makes the interaction quite unintuitive. I noticed that the last plot on a page is not affected by this, but all the rest are.

This can be seen on the original knitr example:

source: https://dl.dropboxusercontent.com/u/15335397/misc/webgl-rmd.Rmd

plots: https://dl.dropboxusercontent.com/u/15335397/misc/webgl-rmd.html

Notice the differences when trying to rotate the first and second figure.

What could be a potential cause? Maybe the problem can be solved by passing some additional parameters to the 3d and rgl plots (was not able to find any)? Or is it a minor bug of knitr and webgl?


回答1:


This is a bug in knitr, and has been fixed in the development version. The reason for it is that rgl includes <script src="CanvasMatrix.js" type="text/javascript"></script> for every plot, even when there are multiple plots on the same page. I have removed this line on knitr's side, so that CanvasMatrix.js is only loaded once. The knitr example you mentioned works now.



来源:https://stackoverflow.com/questions/23021317/rottation-of-r-3d-plots-not-working-properly-with-knitr-and-webgl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!