"

Using transparency to emphasise the story arc

Today’s #rstats #dataviz “make it easy for your readers” tip: use transparency to enhance the storytelling capabilities of your plot.

Author
Affiliation

Building Stories with Data

Published

August 10, 2022

Quick demo with the penguins: two plots (+ code) with identical text and colour schemes - see which one you find easier to read.

First, the “story-neutral” graph

# Code with no transparency tweak
# The reader has to work harder to find the column we're talking about

library(ggplot2)

penguin_palette <- c(
  "Adelie" = "darkorange",
  "Gentoo" = "cyan4",
  "Chinstrap" = "purple"
)

palmerpenguins::penguins |>
  ggplot() +
  geom_bar(aes(x = island, fill = species)) +
  scale_fill_manual(values = penguin_palette) +
  guides(alpha = "none") +
  labs(
    x = "Island",
    y = "",
    title = "There are two species of penguins on Dream Island",
    subtitle = "The total population of Dream Island sits between that of Biscoe and of Torgersen.",
    fill = NULL
  ) +
  theme_minimal()

And now, the transparency emphasis

Note that the alpha range is restricted, so we don’t get alpha = 0 (totally transparent) columns.

Just a few extra lines, but it saves us a lot of time figuring out which column we should be looking at!

# Code with transparency tweak
# The reader can easily see we're talking about Dream Island

palmerpenguins::penguins |>
  dplyr::mutate(
    alpha_value = dplyr::case_when(island == "Dream" ~ 1, TRUE ~ 0)
  ) |>
  ggplot() +
  geom_bar(aes(x = island, fill = species, alpha = alpha_value)) +
  scale_fill_manual(values = penguin_palette) +
  scale_alpha(range = c(0.5, 1)) +
  guides(alpha = "none") +
  labs(
    x = "Island",
    y = "",
    title = "There are two species of penguins on Dream Island",
    subtitle = "The total population of Dream Island sits between that of Biscoe and of Torgersen.",
    fill = NULL
  ) +
  theme_minimal()

Reuse

Citation

For attribution, please cite this work as:
Thompson, Cara. 2022. “Using Transparency to Emphasise the Story Arc.” August 10, 2022. https://www.cararthompson.com/posts/2022-08-10-todays-rstats-dataviz-make-it/.