Skip to contents

Produces an interactive HTML plotly version of the chart that ggplot2::autoplot() would build for the same object. Useful for dashboards, reports, and any context where hovering, zooming and panning matters.

Usage

as_plotly(x, ...)

# Default S3 method
as_plotly(x, ...)

# S3 method for class 'shewhart_chart'
as_plotly(x, tooltip = c("x", "y"), ...)

Arguments

x

A shewhart_chart object.

...

Additional arguments forwarded to plotly::ggplotly().

tooltip

Character vector of aesthetics to display in the hover tooltip, as accepted by plotly::ggplotly(). Defaults to c("x", "y").

Value

A plotly object (S3 class plotly / htmlwidget) ready to print, embed in a Shiny app, or save with htmlwidgets::saveWidget().

Details

This is a separate function rather than an autoplot() argument so that loading shewhartr does not pull plotly (and its full transitive dependency tree) into every R session that uses the package. plotly lives in Suggests; install it explicitly if you want to use this function.

Examples

# \donttest{
if (requireNamespace("plotly", quietly = TRUE)) {
  set.seed(1)
  df  <- data.frame(t = 1:50, y = rnorm(50, mean = 100, sd = 2))
  fit <- shewhart_i_mr(df, value = y, index = t)
  as_plotly(fit)
}
# }