| Title: | Multimodal Access and Interactive Data Representation |
|---|---|
| Description: | Provides accessible, interactive visualizations through the 'MAIDR' (Multimodal Access and Interactive Data Representation) system. Converts 'ggplot2' and Base R plots into accessible HTML/SVG formats with keyboard navigation, screen reader support, and 'sonification' capabilities. Supports bar charts (simple, grouped, stacked), histograms, line plots, scatter plots, box plots, violin plots, heat maps, density/smooth curves, faceted plots, multi-panel layouts (including patchwork), and multi-layered plot combinations. Enables data exploration for users with visual impairments through multiple sensory modalities. For more details see the 'MAIDR' project <https://maidr.ai/>. |
| Authors: | JooYoung Seo [aut, cph], Niranjan Kalaiselvan [aut, cre] |
| Maintainer: | Niranjan Kalaiselvan <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.3.0 |
| Built: | 2026-05-29 12:58:46 UTC |
| Source: | https://github.com/xability/r-maidr |
Combine data from multiple layers in facet processing
combine_facet_layer_data(layer_results)combine_facet_layer_data(layer_results)
layer_results |
List of layer processing results |
Combined data
Combine selectors from multiple layers in facet processing
combine_facet_layer_selectors(layer_results)combine_facet_layer_selectors(layer_results)
layer_results |
List of layer processing results |
Combined selectors
Extract layout from a single leaf ggplot
extract_leaf_plot_layout(leaf_plot)extract_leaf_plot_layout(leaf_plot)
leaf_plot |
The ggplot object |
Layout with title and axes
Recursively extract leaf ggplots in visual order
extract_patchwork_leaves(node)extract_patchwork_leaves(node)
node |
Patchwork node or ggplot object |
List of leaf ggplot objects
Find children matching a type pattern
find_children_by_type(parent_grob, pattern)find_children_by_type(parent_grob, pattern)
parent_grob |
The parent grob to search |
pattern |
The pattern to match in grob names |
Vector of matching child names
These functions provide a robust way to find grob elements and generate CSS selectors, independent of panel structure or hardcoded values. Find grob by element type pattern
find_graphics_plot_grob(grob, element_type, plot_index = NULL)find_graphics_plot_grob(grob, element_type, plot_index = NULL)
grob |
The grob tree to search (typically from ggplotify::as.grob()) |
element_type |
The element type to search for (e.g., "rect", "lines", "points") |
plot_index |
Optional plot index to match (for multipanel layouts) |
Searches recursively through a grob tree to find a grob whose name matches the pattern: graphics-plot-<number>-<element_type>-<number>
The name of the first matching grob, or NULL if not found
Find the panel grob in a grob tree
find_panel_grob(grob_tree)find_panel_grob(grob_tree)
grob_tree |
The grob tree to search |
The panel grob or NULL if not found
Discover panels via gtable layout rows named '^panel-<num>' or '^panel-<row>-<col>' Returns a data.frame with panel_index, name, t, l, row, col
find_patchwork_panels(gtable)find_patchwork_panels(gtable)
gtable |
Gtable object |
Data frame with panel information
Creates a CSS selector that targets SVG elements by their ID pattern, without relying on panel structure or hardcoded values.
generate_robust_css_selector(grob_name, svg_element)generate_robust_css_selector(grob_name, svg_element)
grob_name |
The name of the grob (e.g., "graphics-plot-1-rect-1") |
svg_element |
The SVG element type to target (e.g., "rect", "polyline") |
A robust CSS selector string, or NULL if grob_name is invalid
Creates a robust CSS selector that works regardless of panel structure. This is the main function that layer processors should use.
generate_robust_selector( grob, element_type, svg_element, plot_index = NULL, max_elements = NULL )generate_robust_selector( grob, element_type, svg_element, plot_index = NULL, max_elements = NULL )
grob |
The grob tree to analyze |
element_type |
The element type to search for (e.g., "rect", "lines") |
svg_element |
The SVG element to target (e.g., "rect", "polyline") |
plot_index |
Optional plot index for multipanel layouts |
max_elements |
Optional limit on number of elements to target |
A robust CSS selector string, or NULL if element not found
Get facet group information for a panel
get_facet_groups(panel_info, built)get_facet_groups(panel_info, built)
panel_info |
Panel information from layout |
built |
Built plot data |
List of facet group information
Retrieves the current fallback configuration for MAIDR.
maidr_get_fallback()maidr_get_fallback()
A list with the current fallback settings:
enabled: Logical indicating if fallback is enabled
format: Character string of the image format
warning: Logical indicating if warnings are shown
[maidr_set_fallback()] to configure settings
# Get current settings settings <- maidr_get_fallback() print(settings)# Get current settings settings <- maidr_get_fallback() print(settings)
Disables automatic MAIDR rendering and restores normal plot behavior. After calling this, Base R plots display in the standard graphics window and ggplot2 objects render with the default ggplot2 method.
maidr_off()maidr_off()
Invisible TRUE on success
[maidr_on()] to enable MAIDR rendering
Enables automatic accessible rendering of ggplot2 and Base R plots. In interactive sessions, plots are displayed in the MAIDR interactive viewer. In RMarkdown documents, plots are converted to accessible MAIDR widgets with keyboard navigation and screen reader support.
maidr_on()maidr_on()
Invisible TRUE on success
[maidr_off()] to disable MAIDR rendering
library(maidr) # Enable interception (on by default after library(maidr)) maidr_on() # Now all plots render as accessible MAIDR widgets library(ggplot2) ggplot(mtcars, aes(x = factor(cyl))) + geom_bar() barplot(table(mtcars$cyl))library(maidr) # Enable interception (on by default after library(maidr)) maidr_on() # Now all plots render as accessible MAIDR widgets library(ggplot2) ggplot(mtcars, aes(x = factor(cyl))) + geom_bar() barplot(table(mtcars$cyl))
Creates a Shiny output container for MAIDR widgets using htmlwidgets. This provides automatic dependency injection and robust JavaScript initialization.
maidr_output(output_id, width = "100%", height = "400px")maidr_output(output_id, width = "100%", height = "400px")
output_id |
The output variable to read the plot from |
width |
The width of the plot container (default: "100percent") |
height |
The height of the plot container (default: "400px") |
A Shiny widget output function for use in UI
if (interactive()) { library(shiny) ui <- fluidPage(maidr_output("myplot")) }if (interactive()) { library(shiny) ui <- fluidPage(maidr_output("myplot")) }
Configure how MAIDR handles unsupported plot types or layers. When fallback is enabled, unsupported plots are rendered as static images instead of failing or returning empty data.
maidr_set_fallback(enabled = TRUE, format = "png", warning = TRUE)maidr_set_fallback(enabled = TRUE, format = "png", warning = TRUE)
enabled |
Logical. If TRUE (default), unsupported plots fall back to image rendering. If FALSE, unsupported layers return empty data. |
format |
Character. Image format for fallback: "png" (default), "svg", or "jpeg". |
warning |
Logical. If TRUE (default), shows a warning message when falling back to image rendering. |
Invisibly returns a list of the previous settings.
[maidr_get_fallback()] to retrieve current settings
# Save current settings and restore on exit old_settings <- maidr_get_fallback() on.exit(maidr_set_fallback( enabled = old_settings$enabled, format = old_settings$format, warning = old_settings$warning )) # Disable fallback (unsupported plots will have empty data) maidr_set_fallback(enabled = FALSE) # Use SVG format for fallback images maidr_set_fallback(format = "svg") # Disable warning messages maidr_set_fallback(warning = FALSE) # Configure multiple options maidr_set_fallback(enabled = TRUE, format = "png", warning = TRUE)# Save current settings and restore on exit old_settings <- maidr_get_fallback() on.exit(maidr_set_fallback( enabled = old_settings$enabled, format = old_settings$format, warning = old_settings$warning )) # Disable fallback (unsupported plots will have empty data) maidr_set_fallback(enabled = FALSE) # Use SVG format for fallback images maidr_set_fallback(format = "svg") # Disable warning messages maidr_set_fallback(warning = FALSE) # Configure multiple options maidr_set_fallback(enabled = TRUE, format = "png", warning = TRUE)
This function handles the mismatch between visual layout order (row-major) and DOM element generation order (column-major) in gridSVG.
map_visual_to_dom_panel(panel_info, gtable)map_visual_to_dom_panel(panel_info, gtable)
panel_info |
Panel information from layout |
gtable |
Gtable object |
Visual layout (row-major): 1 2 3 4
DOM order (column-major): 1 3 2 4
Gtable panel name or NULL if not found
Organize subplots into 2D grid structure
organize_facet_grid(subplots, panel_layout)organize_facet_grid(subplots, panel_layout)
subplots |
List of processed subplot data |
panel_layout |
Panel layout information |
2D grid structure
Process a single facet panel
process_facet_panel( plot, panel_info, panel_data, facet_groups, gtable_panel_name, built, layout, gtable, format_config = NULL )process_facet_panel( plot, panel_info, panel_data, facet_groups, gtable_panel_name, built, layout, gtable, format_config = NULL )
plot |
The original plot |
panel_info |
Panel information |
panel_data |
Panel-specific data |
facet_groups |
Facet group information |
gtable_panel_name |
Gtable panel name |
built |
Built plot data |
layout |
Layout information |
gtable |
Gtable object |
format_config |
Optional format configuration from maidr label functions |
Processed panel data
Process a single patchwork panel
process_patchwork_panel( leaf_plot, panel_name, panel_index, row, col, layout, gtable )process_patchwork_panel( leaf_plot, panel_name, panel_index, row, col, layout, gtable )
leaf_plot |
The leaf ggplot object |
panel_name |
Panel name from gtable |
panel_index |
Panel index |
row |
Panel row |
col |
Panel column |
layout |
Layout information |
gtable |
Gtable object |
Processed panel data
Creates a Shiny render function for MAIDR widgets using htmlwidgets. This provides automatic dependency injection and robust JavaScript initialization.
render_maidr(expr, env = parent.frame(), quoted = FALSE)render_maidr(expr, env = parent.frame(), quoted = FALSE)
expr |
An expression that returns a ggplot object |
env |
The environment in which to evaluate expr |
quoted |
Is expr a quoted expression |
A Shiny render function for use in server
if (interactive()) { library(shiny) library(ggplot2) server <- function(input, output) { output$myplot <- render_maidr({ ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_bar(stat = "identity") }) } }if (interactive()) { library(shiny) library(ggplot2) server <- function(input, output) { output$myplot <- render_maidr({ ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_bar(stat = "identity") }) } }
Launches example plots demonstrating MAIDR's accessible visualization capabilities. Each example creates an interactive plot using 'show()'.
run_example(example = NULL, type = c("ggplot2", "base_r"))run_example(example = NULL, type = c("ggplot2", "base_r"))
example |
Character string specifying which example to run. If 'NULL' (the default), lists all available examples. |
type |
Character string specifying the plot system to use. Either '"ggplot2"' (default) or '"base_r"'. |
Available examples include various plot types such as bar charts, histograms, scatter plots, line plots, boxplots, heatmaps, and more.
Each example script creates a plot and calls 'show()' to display it in your default web browser with full MAIDR accessibility features including keyboard navigation and screen reader support.
Invisibly returns 'NULL'. Called for its side effect of displaying an interactive plot in the browser or listing available examples.
[show()] for displaying plots, [save_html()] for saving to file
# List all available examples run_example() if (interactive()) { # Run ggplot2 bar chart example run_example("bar") # Run Base R histogram example run_example("histogram", type = "base_r") }# List all available examples run_example() if (interactive()) { # Run ggplot2 bar chart example run_example("bar") # Run Base R histogram example run_example("histogram", type = "base_r") }
Save a ggplot2 or Base R plot as a standalone HTML file with interactive MAIDR accessibility features.
save_html(plot = NULL, file = "plot.html", use_cdn = NULL, ...)save_html(plot = NULL, file = "plot.html", use_cdn = NULL, ...)
plot |
A ggplot2 object or NULL for Base R auto-detection |
file |
File path where to save the HTML file (e.g., "plot.html") |
use_cdn |
Logical. Controls where MAIDR.js is loaded from:
|
... |
Additional arguments passed to internal functions |
The file path where the HTML was saved (invisibly)
# ggplot2 bar chart library(ggplot2) p <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_bar(stat = "identity") maidr::save_html(p, tempfile(fileext = ".html")) # ggplot2 violin plot p_violin <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_violin(fill = "lightblue", alpha = 0.7) + labs(title = "MPG by Cylinders", x = "Cylinders", y = "MPG") maidr::save_html(p_violin, tempfile(fileext = ".html")) # Base R example (requires interactive session for function patching) if (interactive()) { barplot(c(10, 20, 30), names.arg = c("A", "B", "C")) maidr::save_html(file = tempfile(fileext = ".html")) }# ggplot2 bar chart library(ggplot2) p <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_bar(stat = "identity") maidr::save_html(p, tempfile(fileext = ".html")) # ggplot2 violin plot p_violin <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_violin(fill = "lightblue", alpha = 0.7) + labs(title = "MPG by Cylinders", x = "Cylinders", y = "MPG") maidr::save_html(p_violin, tempfile(fileext = ".html")) # Base R example (requires interactive session for function patching) if (interactive()) { barplot(c(10, 20, 30), names.arg = c("A", "B", "C")) maidr::save_html(file = tempfile(fileext = ".html")) }
Display a ggplot2 or Base R plot as an interactive, accessible visualization using the MAIDR (Multimodal Access and Interactive Data Representation) system.
show(plot = NULL, use_cdn = NULL, shiny = FALSE, as_widget = FALSE, ...)show(plot = NULL, use_cdn = NULL, shiny = FALSE, as_widget = FALSE, ...)
plot |
A ggplot2 object or NULL for Base R auto-detection |
use_cdn |
Logical. Controls where MAIDR.js is loaded from:
|
shiny |
If TRUE, returns just the SVG content instead of full HTML document |
as_widget |
If TRUE, returns an htmlwidget object instead of opening in browser |
... |
Additional arguments passed to internal functions |
Invisible NULL. The plot is displayed in RStudio Viewer or browser as a side effect.
# ggplot2 bar chart library(ggplot2) p <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_bar(stat = "identity") maidr::show(p) # ggplot2 violin plot p_violin <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_violin(fill = "lightblue", alpha = 0.7) + labs(title = "MPG by Cylinders", x = "Cylinders", y = "MPG") maidr::show(p_violin) # Base R example (requires interactive session for function patching) if (interactive()) { barplot(c(10, 20, 30), names.arg = c("A", "B", "C")) maidr::show() }# ggplot2 bar chart library(ggplot2) p <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_bar(stat = "identity") maidr::show(p) # ggplot2 violin plot p_violin <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_violin(fill = "lightblue", alpha = 0.7) + labs(title = "MPG by Cylinders", x = "Cylinders", y = "MPG") maidr::show(p_violin) # Base R example (requires interactive session for function patching) if (interactive()) { barplot(c(10, 20, 30), names.arg = c("A", "B", "C")) maidr::show() }