Show Sidebar Hide Sidebar

Exporting Graphs As Static Images Using Chart Studio in R

How to export R graphs as static images using Chart Studio.

New to Plotly?

Plotly is a free and open-source graphing library for R. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.

Supported File Formats

With the plotly R package, you can export graphs you create as static images in the .png and/or .jpg/.jpeg file formats for free using the Chart Studio web service.

Currently, exporting graphs you create as static images in the .eps, .svg, and/or .pdf format is a feature that is available only to users of Chart Studio Enterprise.

Note: It is important to be aware that R graphs containing WebGL-based traces (i.e. of type scattergl, heatmapgl, contourgl, scatter3d, surface, mesh3d, scatterpolargl, cone, streamtube, splom, and/or parcoords) will include encapsulated rasters instead of vectors for some parts of the image if they are exported as static images in a vector format like .eps, .svg, and/or .pdf.

Exporting Chart Studio Charts As Static Images

To export your R graphs as static images using the Chart Studio web service, you can use the built-in plotly_IMAGE() function.

Create A Chart Studio Account And Get An API Key

To use the plotly_IMAGE() function, you will need to have a Chart Studio account and an API key (which can be found in your Chart Studio account online settings). Learn more about getting started with Chart Studio in R.

Set Environment Variables In Your R Session

Let the R session know about your Chart Studio authorization credentials by setting environment variables using Sys.setenv().

Sys.setenv("plotly_username" = "YOUR USER NAME")
Sys.setenv("plotly_api_key" = "YOUR API KEY")

Use The Development Version Of The plotly R Package

You will also need to be using the development version of the plotly R package in order to use the plotly_IMAGE() function. This can be installed from GitHub using the devtools R package by running the following command in your R session:

devtools::install_github("ropensci/plotly")

Export R Graph As Static Image

The plotly_IMAGE() function exports your R plots as static images using the Chart Studio web service. The image will be stored in a file in the working directory of your R session.

library(plotly)
p <- plot_ly(x = c(1,2,3,4), y = c(2,4,1,3), type = 'scatter', mode = 'lines')
plotly_IMAGE(p, format = "png", out_file = "output.png")

Alternative Methods Of Exporting Graphs As Static Images In R

Local Image Export

As an alternative to using the Chart Studio web service to export your R graphs as static images, you can use the built-in orca() function to export images locally.

Embed R Charts in RMarkdown Documents

See Embedding Graphs in RMarkdown to learn more about embedding R charts in RMarkdown (.Rmd) files.