R:使用 rgl 生成可以在网络浏览器中查看的 3d 可旋转图?

标签 r browser 3d rotation rgl

在 R 统计包的世界中,rgl 允许我生成可以用鼠标旋转的 3D 绘图。有没有办法可以以可移植格式导出这些图,将它们加载到网络浏览器或其他第三方工具中并在那里旋转它们?我对网络浏览器解决方案特别感兴趣,因为这将允许我在内部 wiki 上分享绘图。

如果 rgl 不允许这样做,是否有其他库或策略可以让我完成此任务?

最佳答案

您可以尝试 vrmlgen 软件包。它将生成可以通过浏览器插件显示的 3D VRML 文件;你可以在 VRML Plugin and Browser Detector 找到一个插件.

安装插件后,请尝试以下操作:

require(vrmlgen)
example(bar3d)

注意:示例代码没有在我的浏览器(RStudio、Win7、Chrome)中自动打开,因为路径被破坏了。您可能需要使用:

require(stringr)
browseURL(str_replace_all(file.path(outdir, 'barplot.html'), fixed('\\'), '/'))

如果您不想安装 VRML 插件,您可以使用 X3DOM。您需要一个 converter ,但您的用户应该能够仅使用(现代)浏览器来查看它们。您可能需要修改以下代码才能获得正确的路径:

setwd(outdir)
aopt <- 'C:/PROGRA~1/INSTAN~1/bin/aopt' # Path to conversion program
vrml <- 'barplot.wrl'
x3dom <- 'barx.html'
command <- paste(aopt, '-i', vrml, '-N', x3dom)
system(command)
# LOG   Avalon   Init: 47/616, V2.0.0 build: R-21023 Jan 12 2011
# LOG   Avalon   Read url
# LOG   Avalon   Read time: 0.074000
# ============================================
# Call: writeHTML with 1 param 
# Write raw-data to barx.html as text/html
# WARNING   Avalon   Run NodeNameSpace "scene" destructor and _nodeCount == 3
# WARNING   Avalon   Try to remove nodes from parents
# WARNING   Avalon   PopupText without component, cannot unregister
# WARNING   Avalon   Avalon::exitSystem() call and node/obj left: 0/3331
browseURL(file.path(outdir, 'barx.html'))
setwd(curdir)

关于R:使用 rgl 生成可以在网络浏览器中查看的 3d 可旋转图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7663982/

相关文章:

mysql - 选择 SQL 列以进入 Shiny 状态

r - 按组选择每次运行的第一行

css - 如何确定我的浏览器与 font-family 中的哪种字体匹配?

android - 有什么方法可以在 Android 应用程序中嵌入浏览器?

forms - 浏览器不会提示保存密码

math - 将屏幕上的点反投影回等距投影的世界

c# - 围绕其自身的轴旋转 3D 图元

r - 仅针对重要的拟合绘制 geom_smooth

R: reshape 数据框并创建比例

Android 3D 曲面图