| Title: | Accessibility Toolkit for 'ggplot2', 'plotly', and 'Quarto' |
|---|---|
| Description: | Makes charts and documents accessible across 'ggplot2', 'plotly', and 'Quarto', aligned with the Web Content Accessibility Guidelines (WCAG 2.1, <https://www.w3.org/TR/WCAG21/>). Includes WCAG-tagged palettes, alt-text scaffolds, audits, a document rubric, heading and reading-level checks, 'shiny' ARIA helpers, and a stylesheet for 'DT' and 'DiagrammeR', as employed in Shin et al. (2026) <doi:10.1177/07319487251412879>. |
| Authors: | Mikyung Shin [aut, cre] (ORCID: <https://orcid.org/0000-0001-7907-9193>, affiliation: Illinois State University) |
| Maintainer: | Mikyung Shin <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.8 |
| Built: | 2026-05-23 17:52:48 UTC |
| Source: | https://github.com/mshin77/a11yviz |
Returns a named numeric vector of alpha values for common chart roles.
Use them when setting alpha = in ggplot2::geom_*() or plotly traces.
Alpha lowers the effective contrast a viewer sees, so verify the
composited contrast with a11y_check_palette() when the choice matters.
a11y_alpha_presets()a11y_alpha_presets()
Named numeric vector with elements raw_points, overlay_point,
labels, fill, ci_ribbon, ci_band.
a11y_alpha_presets() a11y_alpha_presets()[["overlay_point"]]a11y_alpha_presets() a11y_alpha_presets()[["overlay_point"]]
Introspects a ggplot or plotly object and emits a sentence scaffold
with chart type, axis labels, ranges, and group counts pre-filled. A
bracketed placeholder marks where the substantive trend description
belongs. Pass the edited string to a11y_alt_text() to attach it.
a11y_alt_template(p)a11y_alt_template(p)
p |
A |
Character scalar.
if (requireNamespace("ggplot2", quietly = TRUE)) { library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) + geom_point() a11y_alt_template(p) }if (requireNamespace("ggplot2", quietly = TRUE)) { library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) + geom_point() a11y_alt_template(p) }
For plotly objects, sets the figure-level aria-label and a hidden
description div. For ggplot, attaches the alt text as an attribute that
Quarto renders as <img alt="...">.
a11y_alt_text(p, text)a11y_alt_text(p, text)
p |
A plotly or ggplot object. |
text |
Character. Concise description for screen readers. |
The object with alt text attached.
if (requireNamespace("ggplot2", quietly = TRUE)) { library(ggplot2) p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() a11y_alt_text(p, "Scatter of car weight against fuel economy.") }if (requireNamespace("ggplot2", quietly = TRUE)) { library(ggplot2) p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() a11y_alt_text(p, "Scatter of car weight against fuel economy.") }
Pair with a CSS rule that defines .screen-reader-only (see a11y_css()).
a11y_announce(text)a11y_announce(text)
text |
Character. Message to announce. |
Character scalar containing HTML.
a11y_announce("Loading results, please wait")a11y_announce("Loading results, please wait")
Generates a semantic aria-label value combining an action, element type,
and optional context. Intended for Shiny UI elements (buttons, inputs).
a11y_aria_label(element_type, action, context = NULL)a11y_aria_label(element_type, action, context = NULL)
element_type |
Character. Element type, e.g. |
action |
Character. Action verb, e.g. |
context |
Character or |
Character scalar suitable for aria-label.
a11y_aria_label("button", "analyze", "readability") a11y_aria_label("input", "search")a11y_aria_label("button", "analyze", "readability") a11y_aria_label("input", "search")
Union of a11y_audit_chart() and a11y_audit_doc(). Prefer the split
functions when one scope is enough.
a11y_audit(p, level = "AA")a11y_audit(p, level = "AA")
p |
A |
level |
|
Data frame with columns criterion, check, status, note.
Join to a11y_rubric() for principle, guideline, and threshold.
Filters an audit data frame to rows with status todo or ok – the
decisions a chart author has to make. Drops rows handled by helpers,
rows that belong to the host document, and rows marked manual / n/a.
a11y_audit_actionable(audit)a11y_audit_actionable(audit)
audit |
Output of |
Data frame with the same columns as audit, filtered.
Returns the chart-relevant rows from the WCAG 2.1 audit: alt text, redundant group encoding, text contrast, text size, non-text contrast, hover/focus, and (at AAA) stronger text contrast.
a11y_audit_chart(p, level = "AA")a11y_audit_chart(p, level = "AA")
p |
A |
level |
|
Data frame with columns criterion, check, status, note.
Returns the host-page rows from the WCAG 2.1 audit: heading hierarchy, text resizing, reflow, body text spacing, and visible keyboard focus.
a11y_audit_doc(level = "AA")a11y_audit_doc(level = "AA")
level |
|
Data frame with columns criterion, check, status, note.
Returns a sentence counting how many checks need a decision, how many pass, and how many are already handled.
a11y_audit_summary(audit)a11y_audit_summary(audit)
audit |
Output of |
Length-1 character vector.
Validates a candidate alt-text string for informative content. Decorative
elements should pass decorative = TRUE and use alt="" in markup.
Companion to a11y_alt_text(), which attaches alt text to a plot object;
this function validates a string before attaching.
a11y_check_alt_text( alt_text, element_type = "image", decorative = FALSE, min_length = 10 )a11y_check_alt_text( alt_text, element_type = "image", decorative = FALSE, min_length = 10 )
alt_text |
Character or |
element_type |
Character. Element type for the warning, e.g. |
decorative |
Logical. If |
min_length |
Integer. Minimum length for informative alt text (default 10). |
TRUE if valid; FALSE with a warning otherwise.
a11y_check_alt_text("Bar chart showing word frequency", "plot") suppressWarnings(a11y_check_alt_text("", "plot")) a11y_check_alt_text("", "icon", decorative = TRUE)a11y_check_alt_text("Bar chart showing word frequency", "plot") suppressWarnings(a11y_check_alt_text("", "plot")) a11y_check_alt_text("", "icon", decorative = TRUE)
Scans a file for three heading defects:
(a) skipped heading levels (e.g., ## followed by ####),
(b) empty headings,
(c) non-descriptive headings (text shorter than min_chars).
These violate WCAG 2.1 Success Criteria 1.3.1 (Info and Relationships),
2.4.6 (Headings and Labels), and 2.4.10 (Section Headings).
a11y_check_headings(path, min_chars = 3)a11y_check_headings(path, min_chars = 3)
path |
Path to a |
min_chars |
Minimum heading text length (after trimming) considered
descriptive. Default |
Data frame with one row per issue, columns line, level,
text, issue. Empty data frame if no issues.
## Not run: a11y_check_headings("paper.qmd") ## End(Not run)## Not run: a11y_check_headings("paper.qmd") ## End(Not run)
Bins point coordinates from geom_point layers to a bins x bins
grid in data space and reports the fraction of points that share a
cell with another point. Treat as a render-resolution proxy for
Success Criterion 1.3.1 (information must remain perceivable). When
overlap is non-zero, alpha may be considered, but composited contrast
must clear 3:1 per Success Criterion 1.4.11.
a11y_check_overlap(p, bins = 100)a11y_check_overlap(p, bins = 100)
p |
A |
bins |
Grid resolution per axis (default 100). |
List with total, obscured, fraction, recommendation.
Computes the contrast ratio of every color against a reference background
and reports whether each meets the WCAG threshold (4.5:1 for AA, 7:1 for
AAA). When alpha < 1, contrast is computed against the alpha-composited
rendered color – the color the viewer actually sees.
Works on any palette – viridis, RColorBrewer, plotly's discrete
sequences, or a custom hex vector.
a11y_check_palette(colors, bg = "#ffffff", level = "AA", alpha = 1)a11y_check_palette(colors, bg = "#ffffff", level = "AA", alpha = 1)
colors |
Character vector of hex codes. |
bg |
Reference background hex(es). Pass a single value (e.g.
|
level |
|
alpha |
Opacity in |
Data frame with columns color, bg, alpha, rendered,
ratio, status.
a11y_check_palette(c("#000000", "#cccccc", "#ff0000")) a11y_check_palette(c("#0072B2"), bg = c("#ffffff", "#1a1a1a"), level = "AA-large") a11y_check_palette(c("#0072B2", "#D55E00"), alpha = 0.7, level = "AA-large")a11y_check_palette(c("#000000", "#cccccc", "#ff0000")) a11y_check_palette(c("#0072B2"), bg = c("#ffffff", "#1a1a1a"), level = "AA-large") a11y_check_palette(c("#0072B2", "#D55E00"), alpha = 0.7, level = "AA-large")
Distinguishability drops fast above seven categories even in CVD-safe palettes; consider faceting, aggregation, or a sequential / ordinal encoding instead.
a11y_check_palette_size(n, max = 7)a11y_check_palette_size(n, max = 7)
n |
Integer; number of categories. |
max |
Integer; recommended maximum. Default |
Named list with n, max, status ("ok" / "todo"), note.
a11y_check_palette_size(5) a11y_check_palette_size(12)a11y_check_palette_size(5) a11y_check_palette_size(12)
Computes Flesch-Kincaid Grade Level and Flesch Reading Ease for the supplied text. Pure base R with a syllable-count heuristic; no external dependencies. Maps to WCAG 2.1 Success Criterion 3.1.5 (Reading Level, AAA).
a11y_check_readability(text)a11y_check_readability(text)
text |
Character vector, single string, or path to a |
Data frame with one row and columns sentences, words,
syllables, flesch_kincaid_grade, flesch_reading_ease.
a11y_check_readability("The cat sat on the mat. The dog ran away.")a11y_check_readability("The cat sat on the mat. The dog ran away.")
For every pair of colors in the palette, computes the WCAG
relative-luminance contrast ratio – the same formula used by
a11y_check_palette(). Pairs below min_ratio (default 3.0, the
WCAG 2.1 Success Criterion 1.4.11 "Non-text Contrast / Graphical Objects"
threshold) are flagged. Two data marks of similar colors may
fail this – viewers cannot tell them apart.
a11y_check_separability(colors, min_ratio = 3)a11y_check_separability(colors, min_ratio = 3)
colors |
Character vector of hex codes. |
min_ratio |
Numeric threshold; default |
Data frame with columns from, to, ratio, status.
a11y_check_separability(c("#1B9E77", "#D95F02", "#7570B3"))a11y_check_separability(c("#1B9E77", "#D95F02", "#7570B3"))
Positive tabindex values above the natural document flow create
unpredictable keyboard navigation. WCAG 2.1.1 (Keyboard) recommends
tabindex = 0 (natural order) or tabindex = -1 (focusable but skipped).
a11y_check_tabindex(tabindex = 0)a11y_check_tabindex(tabindex = 0)
tabindex |
Numeric scalar. |
TRUE if valid; FALSE with a warning if non-numeric or > 100.
a11y_check_tabindex(0) a11y_check_tabindex(-1) suppressWarnings(a11y_check_tabindex(999))a11y_check_tabindex(0) a11y_check_tabindex(-1) suppressWarnings(a11y_check_tabindex(999))
Returns the filesystem path to a11yviz.css, an accessible stylesheet that
makes plotly, DT, DiagrammeR, and static plot images theme-aware and
applies WCAG-aligned defaults for contrast, focus, and text spacing. Use
it in Quarto via css:, in Shiny via tags$link(),
or copy it into a project's www/.
a11y_css(mode = c("default", "shiny"))a11y_css(mode = c("default", "shiny"))
mode |
|
Character path (default) or character vector of paths (shiny).
basename(a11y_css()) length(a11y_css("shiny"))basename(a11y_css()) length(a11y_css("shiny"))
Reads the bundled CSS file(s) returned by a11y_css() and concatenates
them as a single string. Useful for embedding inline in Quarto via
<style> tags or in Shiny via tags$style().
a11y_css_contents(mode = c("default", "shiny"))a11y_css_contents(mode = c("default", "shiny"))
mode |
|
Character scalar of CSS source.
nchar(a11y_css_contents())nchar(a11y_css_contents())
Extracts deterministic plot context (chart type, axes, ranges, group
counts) and passes it to the user's backend function, which calls any
LLM provider and returns the alt-text string. Result is attached to the
plot via a11y_alt_text() when attach = TRUE.
a11y_describe(p, backend, attach = TRUE)a11y_describe(p, backend, attach = TRUE)
p |
A |
backend |
A function |
attach |
If |
The package itself depends on no LLM SDK; the caller supplies the transport. See examples for OpenAI, Gemini, and Ollama backends.
The plot with alt text attached, or the string itself.
## Not run: openai_backend <- function(context) { prompt <- paste( "Write one-sentence WCAG 1.1.1 alt text.", "State chart type, axes, and key trend." ) auth <- paste("Bearer", Sys.getenv("OPENAI_API_KEY")) res <- httr::POST( "https://api.openai.com/v1/chat/completions", httr::add_headers(Authorization = auth), body = list( model = "gpt-4o-mini", messages = list( list(role = "system", content = prompt), list(role = "user", content = jsonlite::toJSON(context, auto_unbox = TRUE)) ) ), encode = "json" ) httr::content(res)$choices[[1]]$message$content } p |> a11y_describe(backend = openai_backend) ## End(Not run)## Not run: openai_backend <- function(context) { prompt <- paste( "Write one-sentence WCAG 1.1.1 alt text.", "State chart type, axes, and key trend." ) auth <- paste("Bearer", Sys.getenv("OPENAI_API_KEY")) res <- httr::POST( "https://api.openai.com/v1/chat/completions", httr::add_headers(Authorization = auth), body = list( model = "gpt-4o-mini", messages = list( list(role = "system", content = prompt), list(role = "user", content = jsonlite::toJSON(context, auto_unbox = TRUE)) ) ), encode = "json" ) httr::content(res)$choices[[1]]$message$content } p |> a11y_describe(backend = openai_backend) ## End(Not run)
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.
a11y_ggplotly( gg, level = "AA", palette = NULL, alt = NULL, tooltip = c("x", "y"), strip_title = TRUE, ... )a11y_ggplotly( gg, level = "AA", palette = NULL, alt = NULL, tooltip = c("x", "y"), strip_title = TRUE, ... )
gg |
A |
level |
WCAG contrast level: |
palette |
Optional palette name applied as plotly's |
alt |
Alt-text override. When |
tooltip |
Aesthetic(s) shown in hover. Default |
strip_title |
Logical; when |
... |
Forwarded to |
A plotly object.
if (requireNamespace("ggplot2", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE) && requireNamespace("palmerpenguins", quietly = TRUE)) { library(ggplot2) p <- ggplot(na.omit(palmerpenguins::penguins), aes(flipper_length_mm, body_mass_g, color = species, shape = species)) + geom_point() + scale_color_a11y("dark2_8") + theme_a11y("AA") p <- a11y_alt_text(p, "Penguin body mass vs flipper length by species.") pl <- a11y_ggplotly(p) inherits(pl, "plotly") }if (requireNamespace("ggplot2", quietly = TRUE) && requireNamespace("plotly", quietly = TRUE) && requireNamespace("palmerpenguins", quietly = TRUE)) { library(ggplot2) p <- ggplot(na.omit(palmerpenguins::penguins), aes(flipper_length_mm, body_mass_g, color = species, shape = species)) + geom_point() + scale_color_a11y("dark2_8") + theme_a11y("AA") p <- a11y_alt_text(p, "Penguin body mass vs flipper length by species.") pl <- a11y_ggplotly(p) inherits(pl, "plotly") }
Sets fonts, axis styling, hover-label colors, legend position, and an
accessible categorical colorway. Targets WCAG 2.1 contrast (1.4.3,
1.4.6, 1.4.11) and resizability (1.4.4). Font sizes are package
defaults, not WCAG-mandated minimums. Returns the plotly object so it
can stay in a |> chain.
a11y_layout(p, level = "AA", palette = "dark2_8")a11y_layout(p, level = "AA", palette = "dark2_8")
p |
A plotly object (from |
level |
|
palette |
Discrete palette name applied as plotly's |
Modified plotly object.
Adds only the non-destructive moves: attaches alt text, and raises the base
text size to the WCAG minimum only when the current size is below it.
Palette, theme, legend, and geom aesthetics stay intact. Suitable for
retrofitting charts with an existing visual; theme_a11y() and
scale_a11y() are the greenfield path. Pair with a11y_audit_chart() to
surface remaining gaps (color-only encoding, missing alt, hover styling).
a11y_minimum(p, alt = NULL, level = "AA")a11y_minimum(p, alt = NULL, level = "AA")
p |
A |
alt |
Optional alt text attached via |
level |
|
The chart with alt text attached (if supplied) and base text size raised to the level threshold when it was below.
Returns hex codes for a color-vision-aware categorical palette. Most
palettes are runtime wrappers around RColorBrewer::brewer.pal() so the
authoritative colors stay in their source package.
a11y_palette(name = "dark2_8", n = NULL, bg = NULL)a11y_palette(name = "dark2_8", n = NULL, bg = NULL)
name |
Discrete palette name. Built-in: |
n |
Optional number of colors. Defaults to the palette's full size (truncates from the start when smaller). |
bg |
Plot background context. One of |
Character vector of hex codes (e.g., "#1B9E77"). For sequential
gradients, see a11y_palette_seq().
a11y_palette("dark2_8") a11y_palette("aaa_5") a11y_palette("dark2_8", n = 4)a11y_palette("dark2_8") a11y_palette("aaa_5") a11y_palette("dark2_8", n = 4)
Returns the low/mid/high anchor colors for a diverging gradient. Most
palettes resolve at runtime from RColorBrewer. *_dual variants pick
mid-saturation Brewer positions whose endpoints clear non-text 3:1 on
both white and #1a1a1a dark backgrounds. coolwarm_aaa is a custom
built-in whose endpoints both clear AAA on white only.
a11y_palette_div(name = "rdbu")a11y_palette_div(name = "rdbu")
name |
One of |
Named list with elements low, mid, high (hex codes for the
diverging anchors). To materialize an N-step gradient, pass the list to
a color interpolator (e.g., grDevices::colorRampPalette()).
a11y_palette_div("rdbu") a11y_palette_div("rdbu_dual")a11y_palette_div("rdbu") a11y_palette_div("rdbu_dual")
Returns the source spec, resolved colors, and WCAG metadata for a
discrete palette. For continuous palettes, see a11y_palette_div() and
a11y_palette_seq().
a11y_palette_info(name = "dark2_8")a11y_palette_info(name = "dark2_8")
name |
Discrete palette name. Built-in: |
Named list with name, colors, safe_on, purpose, notes,
plus the source spec fields.
a11y_palette_info("aaa_5")a11y_palette_info("aaa_5")
Lists discrete, diverging, and sequential palettes in one data frame.
a11y_palette_list(type = NULL)a11y_palette_list(type = NULL)
type |
Optional filter: |
Data frame with columns name, type, source, n,
safe_on, purpose. n is NA for continuous palettes. For the
notes field of a single palette, call a11y_palette_info().
a11y_palette_list() a11y_palette_list(type = "diverging")a11y_palette_list() a11y_palette_list(type = "diverging")
Returns a viridisLite spec (option, begin, end, direction) for a
sequential gradient. Use directly with ggplot2::scale_*_viridis_c() or
via scale_fill_a11y_seq(). Pass n = to materialize hex codes.
a11y_palette_seq(name = "cividis", n = NULL)a11y_palette_seq(name = "cividis", n = NULL)
name |
One of |
n |
Optional integer. If supplied, returns |
Named list with elements option, begin, end, direction –
a viridisLite specification, NOT a color vector. Pass n = to
materialize hex codes.
a11y_palette_seq("cividis") a11y_palette_seq("viridis", n = 7)a11y_palette_seq("cividis") a11y_palette_seq("viridis", n = 7)
Plotly ships several discrete categorical sequences (from plotly.js). This helper computes WCAG contrast statistics for each one against a reference background so users can pick a sequence that passes their contrast bar.
a11y_plotly_sequences(bg = "#ffffff", level = "AA")a11y_plotly_sequences(bg = "#ffffff", level = "AA")
bg |
Reference background hex (default |
level |
|
Data frame with one row per sequence: name, n,
min_ratio, median_ratio, n_pass, pct_pass.
a11y_plotly_sequences() a11y_plotly_sequences(level = "AAA")a11y_plotly_sequences() a11y_plotly_sequences(level = "AAA")
Returns the chart-relevant subset of WCAG 2.1 success criteria, with the
AA / AAA threshold and the a11yviz function that addresses it. Joins
to a11y_audit() on the criterion column.
a11y_rubric(level = NULL)a11y_rubric(level = NULL)
level |
Optional filter: |
Data frame with columns criterion, name, level,
threshold_aa, threshold_aaa, a11yviz_function. Pass any
criterion value to a11y_wcag_url() for the spec link.
a11y_rubric() a11y_rubric(level = "AAA")a11y_rubric() a11y_rubric(level = "AAA")
Renders the swatches of a built-in palette and overlays each color's
contrast ratio against bg, plus a pass/fail label for level.
a11y_show_palette(name = "dark2_8", bg = "#ffffff", level = "AA")a11y_show_palette(name = "dark2_8", bg = "#ffffff", level = "AA")
name |
Discrete palette name. See |
bg |
Reference background hex (default |
level |
|
A ggplot object.
if (requireNamespace("ggplot2", quietly = TRUE)) { a11y_show_palette("dark2_8") }if (requireNamespace("ggplot2", quietly = TRUE)) { a11y_show_palette("dark2_8") }
Returns the spacing ratios specified in WCAG Success Criterion 1.4.12 (Text Spacing, Level AA). All values are multiples of the font size.
a11y_text_spacing_ratios()a11y_text_spacing_ratios()
Named numeric vector with line_height, paragraph, letter,
word.
a11y_text_spacing_ratios() a11y_text_spacing_ratios()[["line_height"]]a11y_text_spacing_ratios() a11y_text_spacing_ratios()[["line_height"]]
Returns a deep link to the W3C WCAG 2.1 specification entry for one or more success criteria.
a11y_wcag_url(criterion)a11y_wcag_url(criterion)
criterion |
Character vector of success-criterion numbers (e.g.,
|
Character vector of URLs the same length as criterion. Returns
the spec root URL for unrecognised values.
a11y_wcag_url("1.4.3") a11y_wcag_url(c("1.1.1", "2.4.7", "4.1.3"))a11y_wcag_url("1.4.3") a11y_wcag_url(c("1.1.1", "2.4.7", "4.1.3"))
Applies the most common transforms in one call: theme plus color and fill palettes for ggplot, or layout plus palette for plotly.
make_a11y(p, level = "AA", palette = "dark2_8", alt = NULL)make_a11y(p, level = "AA", palette = "dark2_8", alt = NULL)
p |
A ggplot or plotly object. |
level |
|
palette |
Categorical palette name passed to |
alt |
Optional alt-text string. |
The transformed object.
if (requireNamespace("ggplot2", quietly = TRUE)) { library(ggplot2) p <- ggplot(mpg, aes(class, fill = drv)) + geom_bar() make_a11y(p, palette = "dark2_8", alt = "Vehicle classes by drivetrain.") }if (requireNamespace("ggplot2", quietly = TRUE)) { library(ggplot2) p <- ggplot(mpg, aes(class, fill = drv)) + geom_bar() make_a11y(p, palette = "dark2_8", alt = "Vehicle classes by drivetrain.") }
Opens a Shiny app comparing default ggplot2 output against the
accessible theme, palette, and alt-text helpers, with a per-criterion
WCAG audit. Requires shiny, bslib, ggplot2, and DT; missing
packages are flagged at launch.
run_app(host = "127.0.0.1", port = 8000, launch_browser = TRUE, ...)run_app(host = "127.0.0.1", port = 8000, launch_browser = TRUE, ...)
host |
Network host (default |
port |
Port (default |
launch_browser |
Open the default browser (default |
... |
Passed to |
Invisibly, the return value of shiny::runApp().
if (interactive()) run_app()if (interactive()) run_app()
Categorical palettes that meet WCAG 1.4.1 (Use of Color) by being distinguishable to viewers with color vision differences.
scale_color_a11y(palette = NULL, level = "AA", ...) scale_fill_a11y(palette = NULL, level = "AA", ...)scale_color_a11y(palette = NULL, level = "AA", ...) scale_fill_a11y(palette = NULL, level = "AA", ...)
palette |
One of |
level |
WCAG contrast level. |
... |
Passed to |
A ggplot2 scale.
if (requireNamespace("ggplot2", quietly = TRUE) && requireNamespace("palmerpenguins", quietly = TRUE)) { library(ggplot2) pg <- na.omit(palmerpenguins::penguins) ggplot(pg, aes(flipper_length_mm, body_mass_g, color = species)) + geom_point() + scale_color_a11y() ggplot(pg, aes(species, fill = island)) + geom_bar() + scale_fill_a11y("set2_8") }if (requireNamespace("ggplot2", quietly = TRUE) && requireNamespace("palmerpenguins", quietly = TRUE)) { library(ggplot2) pg <- na.omit(palmerpenguins::penguins) ggplot(pg, aes(flipper_length_mm, body_mass_g, color = species)) + geom_point() + scale_color_a11y() ggplot(pg, aes(species, fill = island)) + geom_bar() + scale_fill_a11y("set2_8") }
ggplot2 scales for diverging gradients with anchor colors sourced from
a11y_palette_div().
scale_color_a11y_div(palette = "rdbu", ...) scale_fill_a11y_div(palette = "rdbu", ...)scale_color_a11y_div(palette = "rdbu", ...) scale_fill_a11y_div(palette = "rdbu", ...)
palette |
One of |
... |
Passed to |
A ggplot2 scale.
ggplot2 scales for sequential viridisLite gradients sourced from
a11y_palette_seq(). The default "cividis" remains readable in
greyscale and spans the full lightness range.
scale_color_a11y_seq(palette = "cividis", ...) scale_fill_a11y_seq(palette = "cividis", ...)scale_color_a11y_seq(palette = "cividis", ...) scale_fill_a11y_seq(palette = "cividis", ...)
palette |
One of |
... |
Passed to |
A ggplot2 scale.
Adds a ggplot2::theme that applies WCAG 2.1 contrast settings plus
the package's recommended font sizes. Compose with + like any other
theme. Title, axis title, and legend sit at the body floor (12 pt AA /
14 pt AAA); axis tick text drops 2 pt below.
theme_a11y(level = "AA", base_family = "", dark = FALSE)theme_a11y(level = "AA", base_family = "", dark = FALSE)
level |
WCAG contrast level: |
base_family |
Font family. Defaults to system sans. |
dark |
Logical; if |
A theme object.
if (requireNamespace("ggplot2", quietly = TRUE)) { library(ggplot2) ggplot(mtcars, aes(mpg, wt)) + geom_point() + theme_a11y() }if (requireNamespace("ggplot2", quietly = TRUE)) { library(ggplot2) ggplot(mtcars, aes(mpg, wt)) + geom_point() + theme_a11y() }