Skip to contents

Converts a plot_compare() pc_interactive result to a plotly::plotly htmlwidget, applying the hover-band JavaScript for dotplots. Useful in knitr/Quarto documents where the object should be the direct return value of the chunk so that knitr embeds it correctly.

Usage

as_plotly(x, height = NULL, width = NULL, ...)

Arguments

x

A pc_interactive object returned by plot_compare(..., interactive = TRUE).

height

Numeric or NULL. Widget height in pixels passed to plotly::ggplotly(). NULL (default) lets plotly choose its own default height (~400 px), which is often too short when the plot has multiple facet panels each showing many varieties. A sensible rule of thumb: 180 px per panel row (e.g. height = 700 for 4 panels in a 2 x 2 grid).

width

Numeric or NULL. Widget width in pixels. NULL (default) uses 100 % of the container width.

...

Unused; included for future extensibility.

Value

A plotly::plotly htmlwidget.

Examples

if (FALSE) { # \dontrun{
# Single-group dotplot -- default height is fine
as_plotly(plot_compare(res, type = "dotplot", interactive = TRUE))

# Four-panel dotplot -- set a taller height so panels don't overlap
as_plotly(plot_compare(res, type = "dotplot", interactive = TRUE),
          height = 700)
} # }