Skip to contents

Converts a ggplot to a plotly object and replaces any expression() axis labels with their HTML equivalents using an internal lookup table. This ensures mathematical notation renders correctly in both static (PDF) and interactive (Shiny/plotly) contexts.

Usage

av_finalize_plotly(p, tooltip = "text")

Arguments

p

A ggplot object.

tooltip

Character vector of aesthetics for plotly tooltips (default "text").

Value

A plotly object with HTML-formatted axis labels.

Examples

example_file <- system.file(
  "extdata", "bcl11a_rs1427407_example.csv", package = "AlphaVaR"
)
obj <- av_import_csv(example_file) |>
  av_calc_enrichment(group_by = "output_type")
#> Reading bcl11a_rs1427407_example.csv ...

p <- av_plot_enrichment(obj, style = "bar")

# plotmath renders correctly in PDF but arrives as literal text in plotly.
p$labels$x
#> expression(-log[10](p[adj]))

pp <- av_finalize_plotly(p)
plotly::plotly_build(pp)$x$layout$xaxis$title$text
#> [1] "-log<sub>10</sub>(p<sub>adj</sub>)"