【问题标题】:How to plot3d in the inner plots window of RStudio如何在 RStudio 的内部绘图窗口中绘制 3d
【发布时间】:2016-07-29 15:17:57
【问题描述】:

我正在使用plot3d {rgl} 绘制一个 3d 图形,但它显示在外部窗口框架上,因此,它没有在 markdown html/pdf 文件中捕获。有没有办法可以在 RStudio 的内部绘图窗口中绘制图形,以便在编译笔记本时捕获它?

【问题讨论】:

    标签: r


    【解决方案1】:

    没有。 rgl 使用完全不同的绘图系统。 Yihui Xie 的knitr hook documentation 解释了如何使用rgl.snapshot() 函数将rgl 输出包含在knitr 文档中:

    knit_hooks$set(rgl = function(before, options, envir) {
      if (!before) {
        ## after a chunk has been evaluated
        if (rgl.cur() == 0) return()  # no active device
        name = paste(options$fig.path, options$label, sep = '')
        rgl.snapshot(paste(name, '.png', sep = ''), fmt = 'png')
        return(paste('\\includegraphics{', name, '}\n', sep = ''))
      }
    })
    

    (然后在你的块选项中使用rgl=TRUE)。您还可以将输出包含为interactive webgl element in an HTML document。如果您使用knitr spin 选项(请参阅here),您应该能够包含如下行

    #+ my_rgl_plot, rgl=TRUE
    

    在你的情节设置块选项之前。

    【讨论】:

    • 非常感谢您的回复。我试过了,但是在生成多个图的循环中,它不起作用。
    • 你能举一个可重现的例子吗?您可能需要构建自己的代码以每次运行rgl.snapshot,然后将结果合并到输出中(即,这对于笔记本格式可能有点过于复杂,显式编写.rmd 文件可能比在其中工作更容易笔记本的局限性)
    • 非常感谢您的帮助,我找到了解决方案stackoverflow.com/questions/38664432/…
    猜你喜欢
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    • 2012-08-28
    相关资源
    最近更新 更多