
Improve keyboard accessibility for plotly legends
Source:R/ro_ply_keyboard_nav_legend.R
ro_ply_keyboard_nav_legend.RdArguments
- fig
A
plotlyobject (fromplotly::plot_ly()orplotly::ggplotly()).
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.
See also
Other ggplotly:
ro_ply_cursor(),
ro_ply_disable_toolbar(),
ro_ply_keyboard_nav_barchart(),
ro_ply_keyboard_nav_bargraph(),
ro_ply_keyboard_nav_linechart(),
ro_ply_keyboard_nav_trendline()
Other plotly:
ro_ply_add_theme(),
ro_ply_cursor(),
ro_ply_dim(),
ro_ply_disable_toolbar(),
ro_ply_focus_linechart(),
ro_ply_keyboard_nav_barchart(),
ro_ply_keyboard_nav_bargraph(),
ro_ply_keyboard_nav_linechart(),
ro_ply_keyboard_nav_trendline(),
ro_ply_legend_theme(),
ro_ply_theme(),
ro_ply_title()
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
} # }