Search code examples
rpdfplotly

Export plot from plotly into PDF


I use package plotly in order to make some plots. And the end my intention is to put this plot with high resolution in pdf. I don't know way but ggplot2 give me permission to do this, but with plotly I can't use option from R-Studio and convert directly into PDF. You can see that on pic below:

enter image description here

In order to fix this problem I try to do this with this lines of code:

 pdf(file=paste("FINAL_plot.pdf",sep=""),width=10, height=5)
          
          op <- par(mgp=c(1,0,0),mar=c(2, 2, 1, 1),# Room for the title and legend: 1_bottom,2_left,3_up,4_right
                    mfrow=c(1,2))
          
          plot(FINAL_plot)

          
          dev.off()

But unfortunately this lines of code didn't work and PDF is empty. So can anybody help me how to resolve this problem ?


Solution

  • Orca is now deprecated. You now must use Kaleido to install. In similarity to Orca, you must first have the Kaleido library installed on your OS. To install:

    install.packages('reticulate')
    reticulate::install_miniconda()
    reticulate::conda_install('r-reticulate', 'python-kaleido')
    reticulate::conda_install('r-reticulate', 'plotly', channel = 'plotly')
    reticulate::use_miniconda('r-reticulate')
    

    To export:

    library(plotly)
    kaleido(FINAL_plot, "FINAL_plot.pdf")