Trying to put colors together in R can difficult. I think most people search google for
ggplot2 colors and end up looking at some funky image of all the color names that work in R. These colors are from the X11 colors that were developed in the 1980s. Unfortunately, they have inconsistent names and the lightness/saturation are all over the place. Using
simplecolors gives you access to a smaller, consistent set of colors. It is similar to the palette tool you might be used to with Microsoft Word or Tableau. You use these colors in the same way you would use
"blue" to color text or chart elements. Here are the 165 colors that are available
sc() stands for simplecolors. In base R, you would call the colors you need as
simplecolors it is very similar but with
The key is that you can add modifiers
The naming convention is standardized: there are 4 types of saturation, 8 hues, and 5 levels of lightness plus a greyscale. To use a color, just combine the 3 parts:
By default, the outputs are hex codes and
simplecolors can be used anywhere you can use a hex code.
For the rest of this tutorial I’m going to show you how to use this package to enhance your color choices in
ggplot2. First, let’s look at the output of base R colors. Although the terms “lightblue” and “navyblue” are common ways to talk about the lightness of blue, when we call them as raw colors they don’t have the same “feel” as they go light to dark.
library(ggplot2) library(simplecolors) p <- ggplot(mpg, aes(y = drv, fill = drv)) + geom_bar() p + scale_fill_manual(values = c("lightblue", "blue", "navyblue"))
Let’s see what it looks like with the
Again, these are just hex codes. The above code is the same as writing
Each hue has it’s own helper function. Our last example can be simplified using
sc(), these helper functions returns hex codes
and in each of these you can adjust the lightness and saturation
You can also go across palettes. Let’s use base R colors again
We could call them with
sc("blue", "violet", "red") but we can also call them with the first letter of each color using
We can brighten or dull the saturation with the argument
sat = ...
and we can lighten or darken with the argument
light = ...
I tried to keep the first initial for each color unique. For example, I chose “violet” over “purple” so it didn’t compete with “pink” but there was no getting around “green” and “grey”. For this reason, you must call grey with “Gy”
You can also use the
simplecolors to make a gradient
library(dplyr) ggplot(mpg, aes(cty, hwy, color = hwy)) + geom_count(alpha = 0.8) + scale_color_gradient( low = sc("brightorange3"), high = sc("brightviolet3") )
For the palettes (
sc_across(), etc.), you can get more info about the colors using the
return = ... argument.
or a table
At anytime, you can see all of the colors using