简体   繁体   中英

How to plot3d in the inner plots window of RStudio

I am plotting a 3d graph using plot3d {rgl} but it is displayed on an external window frame, and for that reason, it is not captured in the markdown html/pdf file. Is there a way that I can plot the graph in the inner plots window of RStudio so that it can be captured when I compile the notebook?

No. rgl uses a completely different plotting system. Yihui Xie's knitr hook documentation explains how to use the rgl.snapshot() function to include rgl output in a knitr document:

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 = ''))
  }
})

(then use rgl=TRUE in your chunk options). You can also include the output as an interactive webgl element in an HTML document . If you use the knitr spin option (see here ), you should be able to include a line like

#+ my_rgl_plot, rgl=TRUE

before your plot to set the chunk options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM