Skip to contents

[toegankelijkheid]

Usage

ro_ply_keyboard_nav_legend(fig)

Arguments

fig

A plotly object (from plotly::plot_ly() or plotly::ggplotly()).

Value

A plotly object with improved legend accessibility.

Details

Makes the legend of a plotly or ggplotly plot accessible via keyboard. Users can use Tab to focus legend items and activate them with Enter or Space. Focus indication is only shown when navigating with the keyboard. ARIA attributes are added for screen readers.

Examples

if (FALSE) { # \dontrun{
data <- tidyr::tibble(
  expand.grid(`Age group` = c("A", "B", "C", "D", "E"), `Sex` = c("Man", "Vrouw")),
  `Number of Cases` = sample(1:50, 10, TRUE)
)
library(ggplot2)
library(plotly)
p <- ggplot(data, aes(
  x = `Number of Cases`,
  y = `Age group`,
  fill = Sex,
  text = paste0(
    "Leeftijdsgroep: <b>", `Age group`, "</b><br>",
    "Geslacht: <b>", Sex, "</b><br>",
    "Aantal cases: <b>", `Number of Cases`, "</b>"
  )
)) +
  geom_col(position = "dodge") +
  labs(
    x = "Aantal cases",
    y = "Leeftijdsgroep",
    fill = "Geslacht"
  )
fig <- ggplotly(p, tooltip = "text")
fig <- ro_ply_keyboard_nav_barchart(fig)
fig <- ro_ply_keyboard_nav_legend(fig)
fig
} # }