Go to file
Carson Sievert d76e87e573
Updates for recent changes to ggplot2 ggproto guide API (#2315)
2023-11-10 15:21:59 -06:00
.github Handle recent changes to ggplot2's `plot_build()` logic (#2262) 2023-05-05 16:51:23 -05:00
R Updates for recent changes to ggplot2 ggproto guide API (#2315) 2023-11-10 15:21:59 -06:00
data rename mn_res -> res_mn; notes on how to get all reservations 2018-03-27 17:07:03 -05:00
data-raw highlight_key() is a better name than highlight_unit() 2018-06-13 10:49:18 -05:00
demo Add 'plotly_selecting' to acceptable 'on' events (#1280) 2021-11-02 14:33:38 -05:00
inst Fixes/workaround for upcoming (> v3.4.3) ggplot2 release (#2301) 2023-10-10 19:41:06 -05:00
man v4.10.3 release candidate (#2309) 2023-10-22 11:32:05 -05:00
tests Fixes/workaround for upcoming (> v3.4.3) ggplot2 release (#2301) 2023-10-10 19:41:06 -05:00
tools Update to plotly.js v2.5.1 (#2002) 2021-09-21 08:47:34 -05:00
.Rbuildignore Upgrade to plotly.js 2.0 (#1967) 2021-06-22 09:07:40 -05:00
.gitignore Upgrade to plotly.js 2.0 (#1967) 2021-06-22 09:07:40 -05:00
CONDUCT.md Pipeable interface 2015-06-08 01:09:30 -05:00
CONTRIBUTING.md trigger build 2018-10-08 09:01:28 -05:00
DESCRIPTION Start new version 2023-10-22 11:35:20 -05:00
LICENSE assign copyright to the company; include a full license 2017-04-19 16:42:07 -05:00
LICENSE.md Plotly Technologies 2017-04-24 13:28:52 -05:00
NAMESPACE v4.10.1 release candidate (#2202) 2022-11-07 09:24:43 -06:00
NEWS.md Updates for recent changes to ggplot2 ggproto guide API (#2315) 2023-11-10 15:21:59 -06:00
README.md Fix README badges 2022-11-02 14:45:46 -05:00
plotly.Rproj add rstudio project 2015-12-18 12:29:02 -06:00


R-CMD-check CRAN Status CRAN Downloads monthly

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


Install from CRAN:


Or install the latest development version (on GitHub) via {remotes}:


Getting started

Web-based ggplot2 graphics

If you use ggplot2, ggplotly() converts your static plots to an interactive web-based version!

g <- ggplot(faithful, aes(x = eruptions, y = waiting)) +
  stat_density_2d(aes(fill = ..level..), geom = "polygon") + 
  xlim(1, 6) + ylim(40, 100)

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. The ggplotly() function itself has some convenient “high-level” arguments, such as dynamicTicks, which tells plotly.js to dynamically recompute axes, when appropriate. The style() function also comes in handy for modifying the underlying trace attributes (e.g. hoveron) used to generate the plot:

gg <- ggplotly(g, dynamicTicks = "y")
style(gg, hoveron = "points", hoverinfo = "x+y+text", hoverlabel = list(bgcolor = "white"))

Moreover, since ggplotly() returns a plotly object, you can apply essentially any function from the R package on that object. Some useful ones include layout() (for customizing the layout), add_traces() (and its higher-level add_*() siblings, for example add_polygons(), for adding new traces/data), subplot() (for combining multiple plotly objects), and plotly_json() (for inspecting the underlying JSON sent to plotly.js).

The ggplotly() function will also respect some “unofficial” ggplot2 aesthetics, namely text (for customizing the tooltip), frame (for creating animations), and ids (for ensuring sensible smooth transitions).

Using plotly without ggplot2

The plot_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 wont ever support (e.g., surface, mesh, trisurf, etc).

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

Learn more

To learn more about special features that the plotly R package provides (e.g., client-side linking, shiny integration, editing and generating static images, custom events in JavaScript, and more), see https://plotly-r.com. You may already be familiar with existing plotly documentation (e.g., https://plotly.com/r/), which is essentially a language-agnostic how-to guide for learning plotly.js, whereas https://plotly-r.com is meant to be more wholistic tutorial written by and for the R user. The package itself ships with a number of demos (list them by running demo(package = "plotly")) and shiny/rmarkdown examples (list them by running plotly_example("shiny") or plotly_example("rmd")). Carson also keeps numerous slide decks with useful examples and concepts.


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