Package {ggalttext}


Title: Make 'ggplot2' Fully Accessible by Generating Alternative Text
Version: 0.3.0
Description: Generates concise alternative text for data visualizations created with 'ggplot2'. Descriptions are produced by inspecting plot layers, labels, scales, and facets, with support for multiple languages and alternative text stored in plot metadata.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.3
Imports: ggplot2, knitr
Suggests: babynames, ggtext, dplyr, patchwork, testthat (≥ 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-06-21 14:21:21 UTC; josephbarbier
Author: Joseph Barbier [aut, cre, cph]
Maintainer: Joseph Barbier <joseph@ysunflower.com>
Repository: CRAN
Date/Publication: 2026-06-25 11:50:12 UTC

Add alt text to Quarto figures

Description

Call this function once at the top of your Quarto document to include an alternative text for all of your ggplot2 charts.

Usage

enable_auto_alt_text(...)

Arguments

...

Arguments passed to generate_alt_text().

Value

NULL, invisibly


Generate alternative text from a ggplot2 object

Description

generate_alt_text() takes any ggplot2 object and generates a string that describes what contains the chart.

The description isn't meant to exactly describe the chart, nor how it was made. Instead, it tries to be short and gives an overview of what's inside the chart such as:

The text can be generated in: English (default), French or German.

Learn more: https://www.section508.gov/create/alternative-text/

Usage

generate_alt_text(
  p,
  ...,
  lang = c("en", "fr", "de"),
  include_title = TRUE,
  max_chars = 125,
  error_on_excess = FALSE,
  source = c("default", "auto", "origin")
)

Arguments

p

A ggplot object.

...

Must be empty. This argument requires all arguments after p to be named.

lang

Language used for generated text. Defaults to "en" (English). Supported values are "en", "fr" (French), and "de" (German).

include_title

Whether to include the title of the plot, if any, in the alternative text. This is mostly useful to reduce the length of the text.

max_chars

The maximum number of characters allowed (default to 125 as recommended by most references). If above, it will raise a warning. If error_on_excess = TRUE, then it will raise an error.

error_on_excess

Whether to raise an error when the number of characters of the alt text is above max_chars. If FALSE, it will raise a warning.

source

Method used to select alt text. Since ggplot2 objects can include built-in alt text (via labs(alt = "Here goes the text")), choose whether to use that text or the one generated by ggalttext. - "default": always generate alt text with ggalttext. - "auto": use existing alt text when it is non-empty; otherwise generate alt text with ggalttext. - "origin": always return ggplot2::get_alt_text(p) as-is.

Value

A string