Color selection

Author

Claus O. Wilke

Introduction

In this worksheet, you will practice choosing your own colors.

First we need to load the required R packages. Please wait a moment until the live R session is fully set up and all packages are loaded.

Next we set up the data.

We will be working with two datasets that we have seen previously. First, the penguins dataset:

penguins

Second, the temps_months dataset which contains the mean temperature for each month in four different locations.

We will start with a scatter plot of the penguins dataset.

Use the color chooser app to manually pick three colors that are appropriate for a qualitative color scale. Then modify the plot to use this scale.

Hint
ggplot(penguins, aes(body_mass_g, bill_length_mm, color = species)) +
  geom_point(size = 2, na.rm = TRUE) +
  scale_color_manual(
    values = ___ # your colors here 
  )
Solution
ggplot(penguins, aes(body_mass_g, bill_length_mm, color = species)) +
  geom_point(size = 2, na.rm = TRUE) +
  scale_color_manual(
    # this is just an example, there are many possible choices here
    values = c('#BF8A21', '#A74C48', '#17517A')
  )

Now let’s consider this heat map of temperatures in different locations throughout the year.

Use the color chooser app to manually pick four to six colors that are appropriate for a sequential color scale. Then modify the plot to use this scale. (To create a manual color gradient, use scale_fill_gradientn().)

Hint
ggplot(temps_months, aes(x = month, y = location, fill = mean)) + 
  geom_tile() + 
  coord_fixed(expand = FALSE) +
  scale_fill_gradientn(
    colours = ___ # your colors here 
  )
Solution
ggplot(temps_months, aes(x = month, y = location, fill = mean)) + 
  geom_tile() + 
  coord_fixed(expand = FALSE) +
  scale_fill_gradientn(
    # this is just an example, there are many possible choices here
    colours = c('#475010', '#8B9B38', '#C6D77C', '#F4F9E1')
  )