Skip to content

plotly/plotly.R

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

plotly

An R package for creating (and modifying) interactive web-based graphs via plotly's JavaScript graphing library.

Installation

plotly is not (yet) available on CRAN, but you can install it via devtools:

devtools::install_github("ropensci/plotly")

Getting Started

Signup

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")

Introduction

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))

https://plot.ly/~agvd/1153

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")

https://plot.ly/~brnvg/1134

Learn more

Contributing

Stay in touch