Lecture 25

Design with Colorblind in Mind; Facets

Byeong-Hak Choe

SUNY Geneseo

November 4, 2024

Design with Colorblind in Mind

Visualization Principle

Design with Colorblind in Mind

Types of Colorblindness

  • Roughly 8% of men and half a percent of women are colorblind.

  • There are several techniques to make visualization more colorblind-friendly:

    1. Use color palettes that are colorblind-friendly
    2. Use shape for scatterplots and linetype for line charts
    3. Have some additional visual cue to set the important numbers apart

Colorblind-Friendly Color Palettes

ggthemes package

  • The ggthemes package provides various themes for ggplot2 visualization:
    • Accessible color palettes, including those optimized for colorblind viewers.
      • E.g., scale_color_colorblind(), scale_color_tableau()
    • Unique, predefined themes for specific styles
      • E.g., theme_economist(), theme_wsj()

Colorblind-Friendly Color Palettes

ggthemes::scale_color_colorblind()

ggplot( data = mpg,
        mapping = 
          aes(x = displ,
              y = hwy, 
              color = class) ) + 
  geom_point(size = 3) +
  scale_color_colorblind()

  • When mapping color in aes(), we can use scale_color_*()

Colorblind-Friendly Color Palettes

ggthemes::scale_color_tableau()

ggplot( data = mpg,
        mapping = 
          aes(x = displ,
              y = hwy, 
              color = class) ) + 
  geom_point(size = 3) +
  scale_color_tableau()

  • scale_color_tableau() provides color palettes used in Tableau.

ggplot Themes

ggthemes::theme_economist()

ggplot( data = mpg,
        mapping = 
          aes(x = displ,
              y = hwy, 
              color = class) ) + 
  geom_point(size = 3) +
  scale_color_colorblind() +
  theme_economist()

  • theme_economist() approximates the style of The Economist.

ggplot Themes

ggthemes::theme_wsj()

ggplot( data = mpg,
        mapping = 
          aes(x = displ,
              y = hwy, 
              color = class) ) + 
  geom_point(size = 3) +
  scale_color_colorblind() +
  theme_wsj()

  • theme_wsj() approximates the style of The Wall Street Journal.

Facets

Facets

  • Adding too many aesthetics to a plot makes it cluttered and difficult to make sense of.
  • One way to add a variable, particularly useful for categorical variables, is to use facets to split our plot into facets, subplots that each display one subset of the data.

Facets

facet_wrap(~ VAR)

ggplot(data = gapminder,
       mapping = 
         aes(x = log10(gdpPercap), 
             y =lifeExp)) + 
  geom_point(alpha = .4) + 
  facet_wrap( ~ continent)

  • To facet our plot by a single variable, we can use facet_wrap().

Facets

facet_wrap(~ VAR) with nrow

ggplot(data = gapminder,
       mapping = 
         aes(x = log10(gdpPercap), 
             y =lifeExp)) + 
  geom_point(alpha = .4) + 
  facet_wrap( ~ continent,
              nrow = 1)

  • nrow determines the number of rows to use when laying out the facets.

Facets

facet_wrap(~ VAR) with ncol

ggplot(data = gapminder,
       mapping = 
         aes(x = log10(gdpPercap), 
             y =lifeExp)) + 
  geom_point(alpha = .4) + 
  facet_wrap( ~ continent,
              ncol = 1)

  • ncol determines the number of columns to use when laying out the facets.

Facets

facet_wrap(~ VAR) with scales

ggplot(data = gapminder,
       mapping = 
         aes(x = log10(gdpPercap), 
             y =lifeExp)) + 
  geom_point(alpha = .4) + 
  facet_wrap( ~ continent,
              scales = "free_x")

  • scales = "free_x" allow for different scales of x-axis

Facets

facet_wrap(~ VAR) with scales

ggplot(data = gapminder,
       mapping = 
         aes(x = log10(gdpPercap), 
             y =lifeExp)) + 
  geom_point(alpha = .4) + 
  facet_wrap( ~ continent,
              scales = "free_y")

  • scales = "free_y" allow for different scales of y-axis

Facets

facet_wrap(~ VAR) with scales

ggplot(data = gapminder,
       mapping = 
         aes(x = log10(gdpPercap), 
             y =lifeExp)) + 
  geom_point(alpha = .4) + 
  facet_wrap( ~ continent,
              scales = "free")

  • scales = "free" allow for different scales of both x-axis and y-axis