在 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/