class: bottom, title background-image: url(img/ben2.jpg) background-position: 95% 10% background-size: 200px <!-- this slide has the Dog Genetics, LLC logo in the top right corner, added using the "background" image classes above. The text begins on the bottom left corner of the slide --> ## Writing Meaningful Alt Texts for Data Visualizations in R #### R Ladies NYC #### October 10, 2022 #### Liz Hare, PhD<br>@DogGeneticsLLC
Twitter
--- class: middle, center <img style="border-radius: 50%;" src="img/ben2.jpg" alt="DogGenetics logo: a simplified yellow Labrador Retriever head appears to be made of layers of paper" width="250px" /> ## Liz Hare, PhD [
Link
doggenetics.com](http://doggenetics.com/)<br> [
Twitter
@DogGeneticsLLC](https://twitter.com/DogGeneticsLLC)<br> [
GitHub
@LizHareDogs](https://github.com/LizHareDogs)<br> [
Envelope
LizHare@DogGenetics.com](mailto:LizHare@DogGenetics.com) .pull-left[ ] <!--end of pull left --> --- # Today's Topics - What is alt text? - Two Frameworks for thinking about writing alt text - Example - Including alt text in R markdown documents - Questions/Practice alt texts --- # Alt text: What It Is - Attached to images to provide a description for people who use screen reading software. - Required to adhere to accessibility laws - Crucial to make sure your data communication reaches everyone There are blind, low vision, and neurodivergent people in the general population, and there are blind members of the data analysis community, even though we have not been visible. --- # Alt text: What It Does Answers "Why was this image included?" Examples: - It describes the relationship between X and Y in a graph - It describes COVID-19 incidences on a map - It compares four groups on outcome measures in faceted bar charts --- # Alt Text: What It Isn't - **Automatically generated** by AI or text mining - The title - The caption - Axis labels on a graph - A humorous remark These will usually not answer these questions: - "Why am I including this data visualization?" - "What are the data saying?" .footnote[ Humor is allowed, but it shouldn't obscure the message conveyed by the image ] --- # Where is Alt Text? Started in [HTML code](https://en.wikipedia.org/wiki/Alt_attribute). Now appears in places like: - [MS Office](https://support.microsoft.com/en-us/office/add-alternative-text-to-a-shape-picture-chart-smartart-graphic-or-other-object-44989b2a-903c-4d9a-b742-6a75b451c669) - PDFs created with Office - [PDFs created with Adobe Acrobat](https://csuf.screenstepslive.com/s/12867/m/96806/l/1474315-alt text-for-images-in-adobe-acrobat-pdf) - [Twitter posts](https://help.twitter.com/en/using-twitter/picture-descriptions) - New! [Get Twitter to remind you when you forget alt text]() - [Facebook posts](https://www.perkinselearning.org/technology/blog/how-add-alt text-facebook-page) - R markdown [documents](https://bookdown.org/yihui/rmarkdown/) and [slides](https://hugo-academic--silvia.netlify.app/2021-03-16-deploying-xaringan-slides/) .footnote[ Follow links for instructions ] --- # Missing Alt Text Infrastructure? .pull-left[ Places without alt text infrastructure - academic journals - books - magazines - software that helps you create websites and blogs ] .pull-right[ Workarounds - Provide descriptions in text, e.g. describe graphed relationship in Results section of a paper - Provide text descriptions of images as supplementary material when submitting to an academic journal - Use replies or comments in social media if you've forgotten alt text - Provide tables and/or raw data for data visualizations ] --- # Alt Text: How Long Is It? *It depends!* - context - complexity Use your judgement even though - Some media have character limits for alt text - Too many guidelines emphasize brevity - One or two sentences won't be enough for many data visualizations --- # Alt Text For Data Visualization: Ingredients Model .pull-left[ Ingredients (answer these questions): 1. What kind of visualization is it (line graph, scatter plot, bar chart...?) 2. What variables are on the axes? 3. What is the range of the data? 4. What relationship between variables does the data visualization show? ] .pull-right[ **Opinion:** Don't waste my time with 1-3 if you aren't going to include 4. While some automatic alt text processes mine some of this information, I don't want to spend time building a mental model of the graph if I can't find out what the graph *says*. ] .footnote[Ingredients identified in this collaboration: Canelón S, Hare E. (2021) Revealing room for improvement in accessibility within a social media data visualization learning community. csvConf2021 https://github.com/spcanelon/csvConf2021 ] --- # Alt Text for Data Visualization: MIT Visualization Group 4-Levels Model 1. Elements and encoded properties - *title, axes and axis labels, data points* 2. Statistical and relation information - *mean, standard deviation, minimum, maximum* 3. Perceptual and cognitive phenomena - * "y increases linearly with x," "males spend less time in all behaviors than females for all faceted behaviors," "The following states have high incidences: ... "* 4. Contextual and domain-specific insights - *"the change in x at this time point was caused by <something not in the data visualization at all>", "the change in incidence was large"* --- # Link to the Data Providing a link to the data set and/or an HTML-formatted data table allows the user to explore the data on their own. Examples: - COVID-19 incidence map by zip code with a table where the user can look up incidence by zip code - A line graph accompanied by a data set allows the user to explore statistics like mean, median, minimum, maximum, slope Tip: don't put URLs in alt text unless they are very simple; there is no way for a screen reader to activate them --- ## Data Visualization Example 1 Dr. Sheffield covering all the ingredients! .pull-left[ A graph marking diversity through time. X axis: geologic time y axis: number of marine families. The x axis spans from the Ediacaran to the Tertiary with the periods marked. Eons marked below. The Cambrian phase is marked, ending in Cambrian. Paleozoic phase stretches from Ordovician to Permian. Mesozoic- Cenozoic phase stretches from Triassic to Tertiary. ] .pull-right[ Diversity starts low- first big jump occuurs in Cambrian but a larger one occurs during Ordovician. The highest point in the Paleozoic reaches in Ordovician and stays there, except for the 2 major extinctions marked. At the Permian- Triassic, there is a large decrease, and it increases steadily to the end of the graph, except for extinction events. Each of the major mass extinctions are marked (5). 0 is marked as an extinction of Ediacaran biota (but there is no decrease in diversity- this is hypothesized, but not clear what occured). 1: extinction at end of Ordovician. 2: Devonian extinction. 3: Permian extinction. 4: Triassic. 5: Cretaceous. ] --- ## Data Visualization Example Graph <img src="img/diversityThroughTime.jpg" alt="A graph marking diversity through time. X axis: geologic time. y axis: number of marine families. The x asix spans from the Ediacaran to the Tertiary with the periods marked. Eons marked below. The Cambrian phase is marked, ending in Cambrian. Paleozoic phase stretches from Ordovician to Permian. Mesozoic- Cenozoic phase stretches from Triassic to Tertiary. Diversity starts low- first big jump occuurs in Cambrian but a larger one occurs during Ordovician. The highest point in the Paleozoic reaches in Ordovician and stays there, except for the 2 major extinctions marked. At the Permian- Triassic, there is a large decrease, and it increases steadily to the end of the graph, except for extinction events. Each of the major mass extinctions are marked (5). 0 is marked as an extinction of Ediacaran biota (but there is no decrease in diversity- this is hypothesized, but not clear what occured). 1: extinction at end of Ordovician. 2: Devonian extinction. 3: Permian extinction. 4: Triassic. 5: Cretaceous." width="50%" style="display: block; margin: auto;" /> .footnote[ Sepkoski, J. J. (1978). A kinetic model of Phanerozoic taxonomic diversity I. Analysis of marine orders. Paleobiology, 4(3), 223-251. ] --- # Objectivity Report what you perceive about the data without judgement about what they mean. Don't - make assumption about whether values are "good" or "bad" (Jung et al, 2021) - express opinions about variables (Jung et al, 2021; Lundgard et al, 2021) - judge whether a change is small or large (Jung et al, 2021) - conflate correlation with causation .footnote[ Jung C, Mehta S, Kulkarni A, Zhao Y, Kim YS. Communicating Visualizations without Visuals: Investigation of Visualization Alternative Text for People with Visual Impairments. IEEE Transactions on Visualization and Computer Graphics. 2021 Sep 30;28(1):1095-105. Lundgard A, Satyanarayan A. Accessible Visualization via Natural Language Descriptions: A Four-Level Model of Semantic Content. IEEE transactions on visualization and computer graphics. 2021 Sep 30;28(1):1073-83. ] --- class: middle, center #R! --- # Alt Text in R Markdown `fig.alt` is the chunk option that holds your alt text. Include one graphic per chunk ```` ``` {r, altCodeChunk, echo=TRUE, fig.alt = "My Alt Text"} library(knitr) include_graphics("img/ben2.jpg") ``` ```` You can see examples of`.Rmd` code for including alt text for [these very slides](https://LizHareDogs.github.io/RLadiesNYAltText). --- # {ggplot2} Label `alt` You can also specify alt text for a `ggplot` using the `labs(alt = <your-alt text>)` option. ```` ``` {r, plotTrees, echo=TRUE, eval=TRUE, fig.alt=get_alt_text(p1)}} library(knitr) library(ggplot2) p1 <- ggplot(Loblolly, aes(x = age, y = height)) + geom_point(na.rm=TRUE) + labs(alt = "Scatter plot of tree height and age, X axis is age from 3 to 25 [need to find out units], y axis is height from 3.46 to 64.10 [need to find out units]. Guessing they get taller with age.") save(p1, file="p1.Rda") ``` ```` --- # Retrieve your {ggplot} Alt Text `get_alt_text(p1)` <img src="img/gem.png" alt="A fuzzy Golden retriever stands in an inside doorway, looking attentively at the photographer." width="20%" style="display: block; margin: auto;" /> --- # Include Alt Text in Your Markdown Report As a workaround when publications don't support alt-text, you can use `get_alt_text()` to - Use it as descriptive text inside your report - Create a separate document to contain all alt texts for a supplementary file *Make sure your ggplot object is available* when you `get_alt_text()` - save the object in the chunk where you create it - load it in the inline code like `load("p1.Rda"); get_alt_text(p1)` --- # Clunkiness - Impossible to write alt text without seeing the data visualization first - `.Rmd` needs to be edited to include alt text --- # Side Note: Providing Your Graphed Data in a File The [{ggdatasaver)](https://github.com/eliocamp/ggdatasaver) package saves the data that generated a `ggplot`' Useful when: - Journals don't have infrastructure to include alt text (include as supplementary files) - Your students will need to explore the data more fully - You need to preserve confidentiality of data summarized in your plot For plot `p1`: `save_plot_data(p1, file="p1data.zip")` --- # Questions? .pull-left[ #### Thank you! - [R-Ladies NYC](https://www.rladiesnyc.org), for the invitation - [Sarah Sheffield](https://sarahlsheffield.wordpress.com), for the alt text example - [Silvia Canelón](https://silviacanelon.com), for the [Xaringan](https://github.com/yihui/xaringan) template ] .pull-right[ Liz Hare PhD [
Link
doggenetics.com](http://doggenetics.com/)<br> [
Twitter
@DogGeneticsLLC](https://twitter.com/DogGeneticsLLC)<br> [
GitHub
@LizHareDogs](https://github.com/LizHareDogs)<br> [
Envelope
LizHare@DogGenetics.com](mailto:LizHare@DogGenetics.com) ]