• Open Source.
    These libraries are free forever. Your Pro plan helps keep them top notch.
  • Share Online.
    Share charts, dashboards, Jupyter notebooks, and presentations through our enterprise-grade cloud.
  • Engineering Support.
    Get instant chat support from our awesome engineering team.
Show Sidebar Hide Sidebar

Getting Started with Plotly for R

Get started with Plotly's R graphing library to make interactive, publication-quality graphs online.

Getting Started with Plotly for R

Plotly is an R package for creating interactive web-based graphs via the open source JavaScript graphing library plotly.js. As of version 2.0 (November 17, 2015), Plotly graphs are rendered locally through the htmlwidgets framework.

Installation

Plotly is now on CRAN!

install.packages("plotly")

Or install the latest development version (on Github) via devtools:

devtools::install_github("ropensci/plotly")


RStudio users should download the latest RStudio release for compatibility with htmlwidgets.

Initialization for Offline Plotting

By default, Plotly for R runs locally in your web browser or in the R Studio viewer.

library(plotly)
p <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
p

Simply printing the Plotly object will render the chart locally in your web browser or in the R Studio viewer.

Plotly graphs are interactive. Click on legend entries to toggle traces, click-and-drag on the chart to zoom, double-click to autoscale, shift-and-drag to pan.

Initialization for Online Plotting

You can publish your charts to the web with Plotly's web service.

1 - Create a free Plotly account:
A Plotly account is required to publish charts online. It's free to get started, and you control the privacy of your charts.

2 - Save your authentication credentials
Find your authentication API keys in your online settings. Set them in your R session with:

Sys.setenv("plotly_username"="your_plotly_username")
Sys.setenv("plotly_api_key"="your_api_key")

Save these commands in your .Rprofile file to be run every time you start R.

3 - Publish your graphs to Plotly with plotly_POST

library(plotly)
p <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
plotly_POST(p, filename = "r-docs/midwest-boxplots")

filename sets the name of the file inside your online plotly account.

Special Instructions for Plotly On-Premise Users

Your API key for account on the public cloud will be different than the API key in Plotly On-Premise. Visit https://plotly.your-company.com/settings/api/ to find your Plotly On-Premise API key. Remember to replace "your-company.com" with the URL of your Plotly On-Premise server.

If your company has a Plotly On-Premise server, change the R API endpoint so that it points to your company's Plotly server instead of Plotly's cloud.

In your .RProfile write:

Sys.setenv("plotly_domain"="https://plotly.your-company.com")

Remember to replace "your-company" with the URL of your Plotly On-Premise server.

Online Plot Privacy

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to our Premium or Enterprise plans.