Accessibility with R Programming

Gareth Burns

Aim

The aim of this talk is to have a lunch time style presentation on Accessibility when programming with R for Global Accessibility Awareness Day. Their are 2 main aims of this presentation:

  1. Demonstration how to make a a graph using ggplot2 using R programming more accessible to users.

  2. Showcase accessibility tools an R programmer has access to that may be of use to individuals or their colleagues.

What is Accessibility?

There are multiple definition of accessibility and they depend on context. A good definition is “people are not excluded from using something on the basis of experiencing a disability” 1. In addition to having a range of abilities people also access information in different ways - for example people may be reading a report using a screen reader or navigating using a keyboard.

The first step in making our outputs more accessibility is being aware of the issues others may face.

Why is it important?

Accessibility is an important aspect of R programming that is often overlooked. It’s ensuring equitability of the outputs you produce, ensuring the message you’re trying to convey or outputs created are reasonable accessible for everyone. Often this will improve you clarity of your message but also mean it can be consumed by a wider audience and aligned of the ethos of the Exploristics.

Making an accessible graph using ggplot2

A common task in R programming is to produce a graph to convey information on the underlying data, such as a trend or comparison between groups. The idiom is “a picture paints a thousand words” and a well designed and thought out figure can enhance your message but it can also distract from your message or alienate some of your intended audience.

KISS

As programmers get exposed to new technologies they inevitable want to showcase the new skills. This can lead to technology-driven decisions rather than business decisions - think of wrapping ggplot2 with as.plotly . That may not always a good idea1.

Another driver is as others publish complex graphs which can be seen as a proxy for technical competence. People compete to have the most technical graph with lots of functionality but little clarity or purpose.

General Tips

ggplot2 was build on the grammar of graphics and provides is a “philosophy of producing graphs”. This provide a framework to produce accessible graphs but can be abused, that’s why Hadley Wickham refuses to allow dual-axis graphs in ggplot2 and limits the number of categories for comparison.

  1. Use hierarchy and structure (Titles)

  2. Reduce visual noise & clutter (labels, axis, images etc).

  3. Be consistent with style within and between graphs

  4. Use large sans serif fonts

Colour schemes

Users can have a visual impairment that reduce their ability to distinguish colors. Online tools can simulate this. Therefore using color as the only medium to distinguish different groups/categories prevents some of your audience from being able to interpret your chart. Colour should never be the only factor to distinguish groups in your graph.

Default Colour scheme

Consider the default colour scheme only using colour to indicate categories.

*ColourBlindy

ColourBlind Friendly

Alt Text

Some of your audience will use screen readers to view your graphs. Alt text is short for alternative text provides an ability for screen readers to provide an audio description of your graph or image. See Nicola Rennie Alt Text Blog for more details.

This is easily added for a Quarto or RMarkdown document but not for MS Word or PDF.

How to add Alt Text

  1. An alt label is added in ggplot2 using the alt argument of the labs function.
  1. Extracting the alt text ggplot2::get_alt_text(plot)

How to add Alt Text (2)

  1. Add to Code chunks of Quarto or RMarkdown document

    A bar chart showing the mean miles per gallon achieved by cars with 3, 4 or 5 gears. Cars with 3 cars obtained the worst miles per gallon

RStudio Accessibility Features

Full list available on RStudio Accessibility Features

Useful Resources