Show Sidebar Hide Sidebar

Plotly ggplot2 Library

Plotly for ggplot2 is an interactive, browser-based charting library built on the open source javascript graphing library, plotly.js. It works entirely locally, through the HTML widgets framework.
library(plotly)

dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
p <- qplot(carat, price, data=dsamp, colour=clarity)

p <- ggplotly(p)

# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = plotly_POST(p, filename="ggplot2/intro-1")
chart_link
Plotly graphs are interactive. Click on the legend entries to toggle traces, click and drag on the canvas to zoom, shift and click to pan.
library(plotly)

set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]

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

p <- ggplotly(p)


# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = plotly_POST(p, filename="ggplot2/intro-2")
chart_link

ggplotly works by serializing ggplot2 figures into plotly's universal graph JSON. See the ggplot2 ??? plotly test tables for current ggplot2 conversion coverage. Submit issues or contribute on rOpenSci.

Plotly's ggplot2 graphs are hosted online in your plotly account or drawn locally in RStudio. They can be embedded in HTML pages, Knitr documents, or Shiny apps. You don't need to use ggplot2 to use Plotly with R, you can also use Plotly's native R graphing library.

Basic Charts
Statistical Charts
Layout & Style Options
Statistics
Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.