Skip to contents
g1 <- ggplot(data = mtcars,
            mapping = aes(x = mpg,
                          y = disp)) +
  geom_point()
generate_alt_text(g1)
#> [1] "A plot with mpg on the x-axis and disp on the y-axis. The data is displayed using points."

g2 <- ggplot(data = mtcars,
             mapping = aes(x = mpg,
                           y = disp)) +
  geom_point() +
  geom_line()
generate_alt_text(g2)
#> [1] "A plot with mpg on the x-axis and disp on the y-axis. The data is displayed using points, and lines."

g3 <- ggplot(data = mtcars,
             mapping = aes(x = mpg,
                           y = disp)) +
  geom_point() +
  geom_line() +
  labs(title = "Plot title",
       subtitle = "A subtitle giving some more explanation.",
       alt = "Some of my own alt text.")
generate_alt_text(g3)
#> [1] "Plot title. A subtitle giving some more explanation. A plot with mpg on the x-axis and disp on the y-axis. The data is displayed using points, and lines. Some of my own alt text."

g4 <- ggplot(data = mtcars) +
  geom_point(mapping = aes(x = mpg,
                           y = disp)) +
  geom_line(mapping = aes(x = mpg,
                          y = wt))
generate_alt_text(g4)
#> [1] "A plot with mpg on the x-axis and disp on the y-axis. The data is displayed using points, and lines."