Lab 4: Effective Use of Color



Labs

Overview

The purpose of this lab is to help you master the strategic use of color in data visualization. You will work with color for its three main purposes covered in lecture: (a) distinguish groups from each other, (b) represent data values, and (c) highlight particular data points.

This lab directly applies the color packages and resources introduced in the Week 4 lecture slides, including viridis, RColorBrewer, colorspace, and accessibility testing with colorblindr.

Data

We’ll be working with the Palmer Penguins dataset, a modern alternative to the iris dataset. You can load it directly from the palmerpenguins package:

library(palmerpenguins)
data(penguins)

The dataset includes measurements for three penguin species (Adelie, Chinstrap, Gentoo) across three islands, with variables for bill dimensions, flipper length, body mass, and sex.

Packages

You’ll need these packages (install any you don’t have):

library(tidyverse)
library(palmerpenguins)
library(viridis)
library(RColorBrewer)
library(colorspace)
library(ggrepel)

# Optional but recommended:
# library(colorblindr)  # remotes::install_github("clauswilke/colorblindr")
# library(gghighlight)

Lab Tasks

Part 1: Distinguishing Groups (Qualitative Color)

1.1 Create a scatterplot showing bill length vs. bill depth, colored by species. Compare at least three different qualitative palettes:

Reflection: Which palette works best for distinguishing the three species? Why?

1.2 Create a boxplot of body mass by island. Use a colorblind-safe palette from ColorBrewer.


Part 2: Representing Data Values (Sequential & Diverging)

2.1 Create a scatterplot of flipper length vs. body mass, with points colored by bill length (continuous). Try three sequential palettes:

Reflection: Which palette makes it easiest to perceive differences in bill length?

2.2 Calculate mean body mass by species and sex. Create a heatmap using geom_tile() with a diverging color scale.

penguin_summary <- penguins %>%
  drop_na(sex) %>%
  group_by(species, sex) %>%
  summarize(mean_mass = mean(body_mass_g), .groups = "drop")

Part 3: Highlighting Specific Points

3.1 Create a scatterplot of flipper length vs. bill length. Highlight only Gentoo penguins in a bright color; show all others in gray.

3.2 Create a line plot showing penguin counts by year and species. Highlight only Adelie penguins while keeping other species visible in gray.


Part 4: Accessibility Check

4.1 Take one of your plots from Part 1 or 2 and test it for colorblind accessibility.

4.2 Demonstrate double encoding by creating a scatterplot that uses both color AND shape to distinguish groups.


Part 5: Avoiding Common Problems

5.1 Create an example showing the “too many colors” problem, then fix it using selective highlighting and labels with geom_text_repel().

5.2 Create a bar chart of penguin counts by species using:


Finishing Up

When you have finished the above:

  1. Knit your document to PDF
  2. Review your work - Do your color choices communicate effectively?
  3. Include brief reflections where requested
  4. Upload to Canvas

Key Principles to Remember


Resources

Refer to Week 4 lecture slides for:

Recommended readings: