Skip to contents

Wraps plotly::ggplotly() with a11y_layout() and forwards alt text attached via a11y_alt_text(). Strips redundant chart titles. Reserve for the interactive supplement; a static ggplot with alt text is the more accessible default.

Usage

a11y_ggplotly(
  gg,
  level = "AA",
  palette = NULL,
  alt = NULL,
  tooltip = c("x", "y"),
  strip_title = TRUE,
  ...
)

Arguments

gg

A ggplot object.

level

WCAG contrast level: "AA" (default) or "AAA".

palette

Optional palette name applied as plotly's colorway. NULL (default) keeps the ggplot's existing scale.

alt

Alt-text override. When NULL, inherited from attr(gg, "a11y_alt").

tooltip

Aesthetic(s) shown in hover. Default c("x", "y").

strip_title

Logical; when TRUE (default) drops title and subtitle so the host page heading is authoritative.

...

Forwarded to plotly::ggplotly().

Value

A plotly object.

Examples

# \donttest{
if (requireNamespace("ggplot2", quietly = TRUE) &&
    requireNamespace("plotly", quietly = TRUE)) {
  library(ggplot2)
  p <- ggplot(iris, aes(Sepal.Length, Sepal.Width,
                        color = Species, shape = Species)) +
    geom_point() +
    scale_color_a11y("dark2_8") +
    theme_a11y("AA")
  p <- a11y_alt_text(p, "Sepal width vs length by species.")
  pl <- a11y_ggplotly(p)
  inherits(pl, "plotly")
}
#> [1] TRUE
# }