rstats package update

r-how-to
data-visualisation
ggplot2
{monochromeR} now generates a ggplot object, which you can easily feed to useful tools like colorblindr::cvd_grid() to check the accessibility consequences of your colour choices. Here’s a quick demo, and a surprise.
Author
Affiliation

Building Stories with Data

Published

September 28, 2022

## The basic idea

# The basic idea:

library(monochromeR)

generate_palette(
  "purple",
  modification = "go_lighter",
  n_colours = 5,
  view_palette = TRUE
)

{fig-alt=“Five tiles going from”purple” to a lighter purple, with the hex codes for the colours printed in black and white within the top and bottom of each tile.” fig-align=“center”}

The view_palette() function can be used as a stand-alone function, allowing users to quickly view (and show the hex codes / colour names for) any palette they like…

view_palette(
  c(
    wesanderson::wes_palettes$Moonrise1,
    wesanderson::wes_palettes$Moonrise2[1:2]
  )
)

The colours from the specified palette shown as annotated tiles, with the hex codes in black and white within the top and bottom of each colour.

… and feed them to colorblindr::cvd_grid(). First, let’s do that without the labels (and show that monochromeR can work from standard colour names).

monochromeR::view_palette(
  c("red", "yellow", "purple", "green"),
  view_labels = FALSE
)

colorblindr::cvd_grid()

Four coloured rectangles: red, yellow, purple, and green. Each rectangle is of equal width.

Four panels illustrating colour vision variations: Deutanomaly, Protanomaly, Tritanomaly, and Desaturated. Each panel displays distinct vertical stripes highlighting differences in colour perception.

And here is the surprise, where including the the labels proved more useful than I’d realised. Even if the colours are perceived as different, the text may not stand out enough against the background colour for everyone.

monochromeR::view_palette(
  c("red", "yellow", "purple", "green"),
  view_labels = FALSE
)

colorblindr::cvd_grid()

Thanks to charliejhadley for suggesting this update! It’s currently under review with CRAN, so in the meantime, install from GitHub to start using this feature.

github.com/cararthompson/monochromeR

Reuse

Citation

For attribution, please cite this work as:
Thompson, Cara. 2022. “Rstats Package Update.” September 28, 2022. https://www.cararthompson.com/posts/2022-09-28-rstats-package-update-monochromeR/.