get_alt_text: Extract alt text from a plot

View source: R/labels.R

get_alt_textR Documentation

Extract alt text from a plot

Description

This function returns a text that can be used as alt-text in webpages etc. Currently it will use the alt label, added with ⁠+ labs(alt = <...>)⁠, or a return an empty string, but in the future it might try to generate an alt text from the information stored in the plot.

Usage

get_alt_text(p, ...)

Arguments

p

a ggplot object

...

Currently ignored

Value

A text string

Examples

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point()

# Returns an empty string
get_alt_text(p)

# A user provided alt text
p <- p + labs(
  alt = paste("A scatterplot showing the negative correlation between engine",
              "displacement as a function of highway miles per gallon")
)

get_alt_text(p)


ggplot2 documentation built on June 22, 2024, 11:35 a.m.