简体   繁体   中英

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:

在此处输入图像描述

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?

Plotly plots can only be exported using the additional orca command line utility ( https://github.com/plotly/orca )

You would first need to install the orca library on your OS (see https://github.com/plotly/orca#installation for details). After that you can export your plot using

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

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")

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