An R package for creating (and modifying) interactive web-based graphs via plotly's JavaScript graphing library.
plotly is not (yet) available on CRAN, but you can install it via devtools:
devtools::install_github("ropensci/plotly")
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).
Note you can check if you have a username and API key with:
plotly:::verify("username")
plotly:::verify("api_key")
If you use ggplot2, simply call ggplotly()
to make your ggplots online and interactive!
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 = 4) +
geom_smooth(aes(colour = cut, fill = cut)) + facet_wrap(~ cut)
(gg <- ggplotly(p))
Click here to interact with the resulting graph (notice the custom hover text!)
The ggplotly()
function converts a ggplot object to a plotly object, so if you like, you may 'post-process' your ggplot graphs to add custom plotly features, for example:
layout(gg, hovermode = "closest")
plotly also supports certain chart types that ggplot2 doesn't support (such as 3D surface, point, and line plots). You can easily create these (or any other plotly) charts using the high-level interface.
plot_ly(z = volcano, type = "surface")
- We love collaboration! See the wiki and the code of conduct for more information.