Learn R Programming

⚠️There's a newer version (4.10.4) of this package.Take me there.

plotly

An R package for creating interactive web graphics via the open source JavaScript graphing library plotly.js.

Installation

Install from CRAN:

install.packages("plotly")

Or install the latest development version (on GitHub) via devtools:

devtools::install_github("ropensci/plotly")

Getting Started

Web-based ggplot2 graphics

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's custom R interface

plotly.js supports some chart types that ggplot2 doesn't (our cheatsheet provides a nice summary of the available chart types). You can create any of these charts via plot_ly().

plot_ly(z = ~volcano, type = "surface")

We have a number of vignettes which explain the plot_ly() interface in depth as well as numerous examples on the plotly website and bundled with the package.

Capturing plotly events

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:

  1. 2D events (source)
  2. Linked Clicks (source)
  3. Linked Brush (source)

You can also hook into these events without shiny using htmlwidgets::onRender() (example). This, however, requires JavaScript knowledge and makes it much harder to coordinate views between htmlwidgets.

Learn more

We have lots of examples on https://plot.ly/r/ and https://plot.ly/ggplot2/, but a more comprehensive review is also available at https://cpsievert.github.io/plotly_book/

Contributing

Please read through our contributing guidelines. Included are directions for opening issues, asking questions, contributing changes to plotly, and our code of conduct.


Copy Link

Version

Install

install.packages('plotly')

Monthly Downloads

235,016

Version

4.5.6

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Carson Sievert

Last Published

January 14th, 2024

Functions in plotly (4.5.6)

add_data

Add data to a plotly visualization
config

Set the default configuration for plotly
as_widget

Convert a list to a plotly htmlwidget object
colorbar

Modify the colorbar
add_trace

Add trace(s) to a plotly visualization
as.widget

Convert a plotly object to an htmlwidget object
bbox

Estimate bounding box of a rotated string
embed_notebook

Embed a plotly figure as an iframe into a Jupyter Notebook
add_annotations

Add an annotation(s) to a plot
add_fun

Apply function to plot, without modifying data
ggplotly

Create plotly graphs using ggplot2 syntax
export

Export a plotly graph to a static file
event_data

Access plotly user input event data in shiny
hobbs

Hobbs data
geom2trace

Convert a "basic" geoms to a plotly.js trace.
get_figure

Request a figure object
gg2list

Convert a ggplot to a list.
hide_legend

Hide legend
hide_colorbar

Hide color bar(s)
hide_guides

Hide guides (legends and colorbars)
layout

Modify the layout of a plotly visualization
last_plot

Retrieve the last plot to be modified or created.
plotly_build

'Build' (i.e., evaluate) a plotly object
mic

Mic data
plotly_data

Obtain data associated with a plotly graph
knit_print.plotly_figure

Embed a plotly figure as an iframe in a knitr doc
plot_mapbox

Initiate a plotly-mapbox object
plot_ly

Initiate a plotly visualization
offline

Plotly Offline
plot_geo

Initiate a plotly-geo object
plotly_POST

Create/Modify plotly graphs
plotly_json

Inspect JSON sent to plotly.js
schema

Display plotly's plot schema
mutate

Objects exported from other packages
plotly-shiny

Shiny bindings for plotly
plotly

Main interface to plotly
print.plotly_figure

Print a plotly figure object
rangeslider

Add a range slider to the x-axis
plotly_empty

Create a complete empty plotly graph.
plotly_IMAGE

Create/Modify plotly images
signup

Create a new plotly account.
subplot

View multiple plots in a single view
style

Modify trace(s)
wind

Wind data
to_basic

Convert a geom to a "basic" geom.
toRGB

Convert R colours to RGBA hexadecimal colour values
toWebGL

Convert trace types to WebGL