• 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 and ggplot2

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

Plotly for R

Plotly is R package for creating interactive web-based graphs via plotly's JavaScript graphing library, plotly.js. The plotly R libary contains a function ggplotly which will convert ggplot2 figures into graphs drawn with plotly.js which can be saved to your online plotly account or rendered locally.

Build Status


plotly is now available on CRAN.


To install the dev version use:



If you don't already have a plotly account, either signup online or use the signup() function (see the help(signup) page for more details).


Find your credentials in our online settings. Set them in your R session with:


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

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:


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

Converting ggplot figures into Plotly graphs


d <- diamonds[sample(nrow(diamonds), 1000), ]

p <- ggplot(data = d, aes(x = carat, y = price)) +
  geom_point(aes(text = paste("Clarity:", clarity)), size = 4) +
  geom_smooth(aes(colour = cut, fill = cut)) + facet_wrap(~ cut)


Publishing graphs to your online plotly account

You can publish your newly created plotly graph to your online plotly account by using plotly_POST().

plotly_POST(p, "Sample Plotly Chart")
Still need help?
Contact Us

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