Created
September 6, 2022 15:53
-
-
Save jthomasmock/ff348bebc63bab20fc390ca974711453 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(rtweet) | |
| library(ggplot2) | |
| # create a plot, with alt-text labeling | |
| ex_plot <- ggplot(mpg, aes(x = displ, y = hwy)) + | |
| geom_point() + | |
| labs(alt = glue::glue( | |
| "A scattergraph of engine displacement in litres ({range(mpg$displ) |> paste0(collapse = ' to ')}) on the x-axis and highway fuel efficiency in mpg ({range(mpg$hwy) |> paste0(collapse = ' to ')}) on the y-axis. There is a negative, linear trend, where as engine displacement increases, fuel efficiency decreases." | |
| ) | |
| ) | |
| # save img locally | |
| ggsave("ggplot-example.png", ex_plot, height = 4, width = 6, dpi = "retina") | |
| # post tweet with alt-text from ggplot2 | |
| post_tweet( | |
| glue::glue( | |
| "Example of plot w/ alt-text" | |
| ), | |
| media = "ggplot-example.png", | |
| media_alt_text = ex_plot$labels$alt | |
| ) | |
| # Gist URL https://gist.github.com/ff348bebc63bab20fc390ca974711453 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment