An interactive graphing library for R
Install from CRAN:
Or install the latest development version (on GitHub) via devtools:
If you use ggplot2,
ggplotly()converts your static plots to an interactive web-based version!
By default,ggplotly()tries to replicate the static ggplot2 version exactly (before any interaction occurs), but sometimes you need greater control over the interactive behavior. Theggplotly()function itself has some convenient “high-level” arguments, such asdynamicTicks, which tells plotly.js to dynamically recompute axes, when appropriate. Thestyle()function also comes in handy for modifying the underlying trace attributes (e.g. hoveron) used to generate the plot:gg
Moreover, sinceggplotly()returns a plotly object, you can apply essentially any function from the R package on that object. Some useful ones includelayout()(for customizing the layout),add_traces()(and its higher-leveladd_*()siblings, for exampleadd_polygons(), for adding new traces/data),subplot()(for combining multiple plotly objects), andplotly_json()(for inspecting the underlying JSON sent to plotly.js).
Theggplotly()function will also respect some “unofficial” ggplot2 aesthetics, namelytext(for customizing the tooltip),frame(for creating animations), andids(for ensuring sensible smooth transitions).
Using plotly without ggplot2
Theplot_ly()function provides a more direct interface to plotly.js so you can leverage more specialized chart types (e.g., parallel coordinates or maps) or even some visualization that the ggplot2 API won’t ever support (e.g., surface, mesh, trisurf, etc).plot_ly(z = ~volcano, type = "surface")
Please read through our contributing guidelines. Included are directions for opening issues, asking questions, contributing changes to plotly, and our code of conduct.