Getting Started with MAIDR

JooYoung Seo

Introduction to MAIDR

MAIDR (Multimodal Access and Interactive Data Representation) is an R package that makes data visualizations accessible to users with visual impairments. It converts ggplot2 and Base R plots into interactive, accessible formats with:

MAIDR helps data scientists and researchers create inclusive visualizations that everyone can explore, regardless of visual ability.

Installation

Install the development version from GitHub:

# Install the released version from CRAN
install.packages("maidr")

# Or the development version from GitHub:
# install.packages("devtools")
devtools::install_github("xability/r-maidr")

Basic Workflow

MAIDR works with two main functions:

  1. show() - Display an interactive plot in RStudio Viewer or browser
  2. save_html() - Save a plot as an HTML file, with the MAIDR.js library in a lib/ folder beside it

Quick Example: ggplot2 Bar Chart

library(maidr)
library(ggplot2)

# Create sample data
sales_data <- data.frame(
  Product = c("A", "B", "C", "D"),
  Sales = c(150, 230, 180, 290)
)

# Create a bar chart
p <- ggplot(sales_data, aes(x = Product, y = Sales)) +
  geom_bar(stat = "identity", fill = "steelblue") +
  labs(
    title = "Product Sales by Category",
    x = "Product",
    y = "Sales Amount"
  ) +
  theme_minimal()

# Display interactively
show(p)

# Or save as HTML file
save_html(p, "sales_chart.html")

Quick Example: Base R Plot

MAIDR also works with Base R plotting functions:

library(maidr)

# Create a simple barplot
categories <- c("A", "B", "C", "D")
values <- c(150, 230, 180, 290)

barplot(
  values,
  names.arg = categories,
  col = "steelblue",
  main = "Product Sales by Category",
  xlab = "Product",
  ylab = "Sales Amount"
)

# Note: For Base R plots, call show() with NO arguments
# after creating the plot
show()

How maidr hooks into your session

Interactive htmlwidgets: plotly, highcharter and echarts4r

maidr_htmlwidget() takes an interactive chart drawn by plotly, highcharter or echarts4r and returns it with MAIDR attached. MAIDR reads the chart in the browser, through the adapter for the library that draws it, so the widget keeps working everywhere an htmlwidget does: the viewer, htmlwidgets::saveWidget(), this document, and Shiny, where a re-rendered chart is read again.

library(maidr)

# plotly, including ggplotly()
plotly::plot_ly(mtcars, x = ~wt, y = ~mpg, type = "scatter", mode = "markers") |>
  maidr_htmlwidget()

# highcharter
highcharter::hchart(mtcars, "scatter", highcharter::hcaes(wt, mpg)) |>
  maidr_htmlwidget()

# echarts4r
mtcars |>
  echarts4r::e_charts(wt) |>
  echarts4r::e_scatter(mpg) |>
  maidr_htmlwidget()

# In Shiny, wrap the widget inside its own render function
# output$chart <- plotly::renderPlotly(maidr_htmlwidget(plotly::plot_ly(...)))

An echarts4r chart is switched to ECharts’ SVG renderer, which MAIDR needs to highlight the mark being read. While an echarts4r chart shows its legend, the visual highlight is off; audio, text and braille are not affected.

Offline vs CDN Usage

By default, show() and save_html() use the bundled MAIDR.js library, so the result works offline. save_html() writes the library to a lib/ folder beside the file, and the two have to be shared together (zip the folder that holds both): an .html sent on its own loads no MAIDR.js and shows a plain, inaccessible chart. Widgets, knitr documents and Shiny apps auto-detect internet availability and use the CDN when online. You can control this behavior with the use_cdn parameter:

library(maidr)
library(ggplot2)

p <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) +
  geom_bar(stat = "identity")

# Default - bundled files, works offline
show(p)

# Force CDN (requires internet when viewing; loads the latest MAIDR.js)
show(p, use_cdn = TRUE)

# Force bundled/local files (works offline)
show(p, use_cdn = FALSE)

The same parameter works with save_html():

# One self-contained file; needs internet whenever it is viewed
save_html(p, "plot_cdn.html", use_cdn = TRUE)

# The file plus a lib/ folder beside it; works offline
save_html(p, "plot_offline.html", use_cdn = FALSE)

The CDN paths load the latest published MAIDR.js, not the copy bundled with the package, the same as the Python binding. The first CDN document in an R session asks jsDelivr (falling back to the npm registry) which version that is, allowing 3 seconds, and every document in the session names that exact version. When the lookup cannot be made – offline, or blocked – nothing fails: the document names the bundled version, the copy use_cdn = FALSE would serve. Documents rendered with use_cdn = FALSE make no network request at all.

To load a fixed version from the CDN instead, pin it with an option or the MAIDR_CDN_VERSION environment variable (the option wins). A pinned document makes no lookup:

# The version bundled with this package
options(maidr.cdn_version = "bundled")

# A particular release
options(maidr.cdn_version = "4.9.0")

# Back to the latest
options(maidr.cdn_version = NULL)

maidr.cdn_timeout (or MAIDR_CDN_TIMEOUT) changes the time allowed for the lookup. See ?"maidr-options" for the details.

When to use use_cdn = FALSE: - Viewing offline, or sharing with readers who may not have internet access: send the file together with its lib/ folder (zip the two), never the .html alone - Ensuring reproducibility with a specific MAIDR.js version (or pin one on the CDN with maidr.cdn_version)

When to use use_cdn = TRUE: - Attaching or uploading a single file, for readers who will be online - Loading the newest MAIDR.js without updating the R package

The DotPad SDK

One thing an offline document still fetches: the SDK for the DotPad tactile display. maidr.js does not bundle it (its licence does not permit redistribution) and imports the vendor’s copy from jsDelivr the first time a reader connects a DotPad. The document renders, sonifies and brailles without the network; only that first connect needs it.

To keep the DotPad offline as well, serve the SDK yourself and tell maidr where it is before rendering. Options and environment variables of the same names both work; an option wins when both are set:

options(
  maidr.dotpad_sdk_url = "https://intranet.example/dotpad/DotPadSDK-3.0.3.js",
  # Only if the braille engine (liblouis) is not in lib/ beside the module
  maidr.dotpad_asset_base_url = "https://intranet.example/dotpad/lib/"
)

save_html(p, "plot_offline.html", use_cdn = FALSE)

Every document maidr produces (show(), save_html(), widgets, knitr and Shiny) then declares window.MAIDR_DOTPAD_SDK_URL and window.MAIDR_DOTPAD_ASSET_BASE_URL ahead of maidr.js, and the CDN is never asked for the SDK. See ?"maidr-options" for the details.

Exploring Accessible Plots

When you open a MAIDR plot, you can explore it using:

Keyboard Navigation

Key Action
Tab Focus the chart; Shift + Tab leaves it
Left / Right Move between data points
Up / Down Move between series, stacked segments, heat map rows or box plot sections, on a chart that has them
Page Up / Page Down Switch between the layers of a chart that has several
B Toggle braille mode
T Toggle text mode
S Toggle sonification
R Toggle review mode
C Toggle high contrast mode
L, then X, Y or T Announce the x axis label, the y axis label or the title
Space Repeat the current sound
Ctrl + / (Cmd + / on macOS) Show or hide the full keyboard shortcut help

Every other shortcut, including autoplay, jumping to the ends, the command palette, settings and the AI chat, is on the MAIDR controls reference.

Screen Reader Announcements

MAIDR plots include:

Data Sonification

Plots can be heard through:

Quarto reveal.js Slides

A revealjs deck needs nothing special from this package: call maidr_on() once in a setup chunk, as in any other Quarto or R Markdown document, and every plot the deck draws becomes an accessible MAIDR chart.

A chart on a revealjs slide is keyboard reachable on its own: Tab moves into it, the arrow keys explore it, and Shift+Tab hands focus back to the slide, so Space advances the deck again. None of that needs configuring.

What does need attention is a reveal.js behavior that has nothing to do with MAIDR. reveal.js keeps the slides on either side of the current one rendered so that transitions stay smooth, and marking them hidden does not take them out of the tab order — reveal’s own inline style overrides the attribute. On a deck with a chart on every slide, a single Tab can therefore land on an off-screen slide’s chart rather than the one in front of the reader. This is hakimel/reveal.js#1587, open since 2016.

The fix is now on reveal.js master, which marks every slide but the current one inert. It has not reached a published release yet, and Quarto carries its own copy of reveal.js — Quarto 1.10 ships 5.1.0 — so it will arrive in a Quarto release some time after reveal.js cuts one. Nothing will need to change in your deck when it does.

Until then, quarto-revealjs-a11y does the same thing for a Quarto deck. Add it once per project:

quarto add mcanouil/quarto-revealjs-a11y

and enable it in the deck’s front matter:

format:
  revealjs:
    revealjs-plugins:
      - a11y

Use 0.2.3 or newer. Earlier versions took off-slide elements out of the tab order by setting tabindex="-1" on them and could not find them again to put them back, which left the chart on the current slide unreachable as well.

With the extension enabled, each slide gives one Tab to its own chart and Shift+Tab back out. The extension also adds a skip link ahead of the slides, so Shift+Tab lands there rather than on the slide element itself; either way Space still moves to the next slide.

Supported Plot Types

MAIDR supports a comprehensive range of visualizations:

Basic Plot Types

See the Heat Map and Candlestick Examples article for the full candlestick + MA + volume pipeline and the Base R support matrix.

Advanced Plot Types

Experimental Plot Types

Every type above is stable. maidr also reads a longer list of charts as prototypes: none has been through a user study, and each may change without a deprecation period. Here and in the rest of the docs an experimental type is marked [experimental] after its name; a type with no mark is stable. Among them:

The full list is under “Experimental Plot Types” in the README.

Next Steps

Tips for Creating Accessible Plots

  1. Use clear titles - Describe what the plot shows
  2. Label axes properly - Include units of measurement
  3. Choose distinct colors - Ensure good contrast
  4. Add legends - Explain what colors/shapes mean
  5. Keep it simple - Avoid overcrowded visualizations

Getting Help

Learn More