Skip to contents

Transform a ggplot2/plot2 object to an interactive plot using the Plotly R Open Source Graphing Library.

Usage

as_plotly(plot, ...)

plotly_style(plot, ...)

Arguments

plot

A ggplot2 plot.

...

In case of as_plotly(): arguments to pass on to layout() to change the Plotly layout object

In case of plotly_style(): arguments to pass on to style() to change the Plotly style object

Examples

if (requireNamespace("plotly", quietly = TRUE)) {
  mtcars |>
    plot2(mpg, hp) |> 
    as_plotly()
}
#> Using type = "point" since both axes are numeric
if (requireNamespace("plotly", quietly = TRUE)) { mtcars |> plot2(mpg, hp) |> as_plotly(dragmode = "pan") |> plotly_style(marker.line.color = "red", hoverinfo = "y") } #> Using type = "point" since both axes are numeric