alt_textify: Automated generation of alt text

Description Usage Arguments Details Examples

View source: R/alt_textify.R

Description

This function relies on the inclusion of titles and subtitles in plots to generate alt text in an automated way. It also incorporates caption text (hidden by default in wolves_theme()) to add the section where further details can be found so you must remember to specify this when creating plots in order to be able to call alt_textify for complete alt text generation later.

Usage

1

Arguments

fig

the plot to generate alt text for (with title, subtitle and caption labs set)

Details

Extracts the title, subtitle, caption and chart type (based on the first geom_ layer specified) and stitches them together into 3 sentences of alt text. Checks length and gives warning if over 255 characters.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(ggplot2)

p <- ggplot(iris, aes(x = Species, y = Sepal.Length)) +
    geom_boxplot(fill = wwfc_cols("light gold 20")) +
    wolves_theme() +
    labs(title = "Virginica sepals are the longest",
         subtitle = "Sepal length (mm) by species",
         caption = "Comparing plant species",
         y = "")
alt_textify(p)

# to output a text doc with alt text for all the figures within a document,
# you can, for example, add them to a named list and write them all out
# simultaneously
outlist <- purrr::map(list("fig1" = p), alt_textify)
outlist
# paste(names(outlist), outlist, sep = "\n") %>% write_lines("text.txt")

lizardburns/wwplot documentation built on Jan. 5, 2022, 12:26 a.m.