Skip to contents

Convert ggplot2 objects to plotly

Usage

to_plotly(p, html_tags = TRUE, tooltip = "text", ...)

Arguments

p

ggplot2 object

html_tags

Logical. If TRUE, returns the plot as a tagList object.

tooltip

Character. The tooltip to display. Default is "text".

...

Arguments passed on to plotly::ggplotly

width

Width of the plot in pixels (optional, defaults to automatic sizing).

height

Height of the plot in pixels (optional, defaults to automatic sizing).

dynamicTicks

should plotly.js dynamically generate axis tick labels? Dynamic ticks are useful for updating ticks in response to zoom/pan interactions; however, they can not always reproduce labels as they would appear in the static ggplot2 image.

layerData

data from which layer should be returned?

originalData

should the "original" or "scaled" data be returned?

source

a character string of length 1. Match the value of this string with the source argument in event_data() to retrieve the event data corresponding to a specific plot (shiny apps can have multiple plots).

Value

A plotly object.

See also

Examples

x <- data.frame(a = c(1,2,3), b = c(2,3,4))
p <- ggplot2::ggplot(x, ggplot2::aes(x = a, y = b)) + ggplot2::geom_point()
to_plotly(p, html_tags = FALSE)