rggplot2plotsavecirclize

How to save R base graphics as an object?


I have a chord diagram built using the circlize package. Unfortunately, it seems like there is no way to save this as an object. I would like to have the plot be an object (especially a ggplot obkect) so that I can modify some of the surrounding text and export it to xlsx. Any suggestions?

Thanks!


Solution

  • Several options from various packages:

    ggplotify:

    g <- as.grob(~plot(runif(10)))
    grid.draw(g)
    

    cowplot:

    plot(runif(10))
    p1_recorded <- recordPlot()
    ggdraw(p1_recorded)