An R package for creating interactive web graphics via plotly.js.
Install from CRAN:
install.packages("plotly")
Or install the latest development version (on GitHub) via devtools:
devtools::install_github("ropensci/plotly")
If you use ggplot2, ggplotly()
converts your plots to an interactive, web-based version! It also provides sensible tooltips, which assists decoding of values encoded as visual properties in the plot.
library(plotly)
g <- ggplot(faithful, aes(x = eruptions, y = waiting)) +
stat_density_2d(aes(fill = ..level..), geom = "polygon") +
xlim(1, 6) + ylim(40, 100)
ggplotly(g)
If you'd like to see how ggplotly()
does in converting different ggplot2 examples, we host a plotly version of the official ggplot2 documentation. We also have some of our own examples here.
plotly supports some chart types that ggplot2 doesn't (such as 3D surface, point, and line plots). You can create these (or any other plotly) charts using plot_ly()
.
plot_ly(z = volcano, type = "surface")
For a more concise overview of the plot_ly()
interface, see here. You might also find our examples and the figure reference to be helpful.
plotly.js exposes a number of 'standard' events that work consistently across plot types. It's easy to hook into these events using the event_data()
function in shiny apps, as these examples demonstrate:
You can also hook into these events without shiny using htmlwidgets::onRender()
(example). This, however, requires JavaScript knowledge and makes it much harder, if not impossible, to coordinate views between htmlwidgets.
Please read through our contributing guidelines. Included are directions for opening issues, asking questions, contributing changes to plotly, and our code of conduct.