Getting Started with Plotly for R
Plotly is now on CRAN!
Or install the latest development version (on GitHub) via devtools:
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:
Save these commands in your .Rprofile file to be run every time you start R.
3 - Publish your graphs to Plotly with
filename to title the file in your Plotly account.
library(plotly) p <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box") api_create(p, filename = "r-docs-midwest-boxplots")
4 (optional) - Suppress auto open
When following the instructions above,
api_create(p) will auto open the created URL in the browser. To suppress this behavior, you can update your browser options in R:
options(browser = 'false') api_create(p, filename = "r-docs-midwest-boxplots")
Special Instructions for Chart Studio Enterprise Users
Your API key for account on the public cloud will be different than the API key in Chart Studio Enterprise. Visit https://plotly.your-company.com/settings/api/ to find your Chart Studio Enterprise API key. Remember to replace "your-company.com" with the URL of your Chart Studio Enterprise server.
If your company has a Chart Studio Enterprise 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:
Remember to replace "your-company" with the URL of your Chart Studio Enterprise server.
Online Plot Privacy
Plots can be set to three different type of privacies: public, private or secret.
Anyone can view this graph. It will appear in your profile and can appear in search engines. You do not need to be logged in to Plotly to view this chart.
Only you can view this plot. It will not appear in the Plotly feed, your profile, or search engines. You must be logged in to Plotly to view this graph. You can privately share this graph with other Plotly users in your online Plotly account and they will need to be logged in to view this plot. This option is only available for Personal and Professional subscribers.
Anyone with this secret link can view this chart. It will not appear in the Plotly feed, your profile, or search engines. If it is embedded inside a webpage or an IPython notebook, anybody who is viewing that page will be able to view the graph. You do not need to be logged in to view this plot. This option is only available for Personal and Professional subscribers.
By default all plots are set to public. Users with a free account are limited to creating public plots. If you have private storage needs, please visit Plotly products page. If you're a Personal or Professional USER and would like the setting for your plots to be private, you can specify sharing as private:
api_create(filename = "private-graph", sharing = "private")
For more examples on privacy settings please visit R privacy documentation