Save EPS Figures in R Plotly
It is not very common to save figures using EPS format.
One disadvantage of R Plotly is when you want to save figures from plotly, you have to use the “screenshot” buttom in RStudio, but the resulting figures is extremely large and high-quality.
In R, you can use the orca function provided by R Plotly. With the plotly
R package, you can export graphs you create as static images in the .png
, .jpg
/.jpeg
, .eps
, .svg
, and/or .pdf
formats using Orca, an open source command line tool for generating static images of graphs created with Plotly’s graphing libraries.
Installation
As described in Orca, there are several ways to install orca
in your machine
Method 1: Conda (Recommended)
$ conda install -c plotly plotly-orca
Method 2: npm (If you have Node.js installed)
$ npm install -g electron@6.1.4 orca
Method 3: Docker
$ docker pull quay.io/plotly/orca
Orca in RStudio
If you are using Rstudio, you might receive the following error message:
> plotly::orca_serve()
Error: The orca command-line utility is required for this functionality.
Please follow the installation instructions here -- https://github.com/plotly/orca#installation
That’s because RStudio doesn’t recognize the PATH
environment variables for conda
. As suggested by Github issue comment, you can fix this by telling RStudio where conda
located.
Sys.setenv("PATH" = paste(Sys.getenv("PATH"), "[Your Conda /bin/ directory]", sep = .Platform$path.sep))
Now you are able to use orca in RStudio:
> Sys.setenv("PATH" = paste(Sys.getenv("PATH"), "/Users/xx/anaconda3/bin/", sep = .Platform$path.sep))
> plotly::orca_serve()
$port
[1] 5151
$process
PROCESS 'orca', running, pid 59108.
Export R Graphics as Static Images using orca()
For more details, please visit plotly official documentation for exporting static graphics in R. Here’s an example:
library(plotly)
if (!require("processx")) install.packages("processx")
fig <- plot_ly(z = ~volcano) %>% add_surface()
orca(fig, "surface-plot.svg")