The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
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 "red"
or "blue"
to color
text or chart elements. Here are the 165 colors that are available
sc()
functionThis function sc()
stands for
simplecolors. In base R, you would
call the colors you need as c("green", "blue")
In simplecolors
it is very similar but with
sc()
instead sc("green", "blue")
The key is that you can add modifiers
sc("brightgreen2", "mutedblue3")
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:
optional saturation | hue | lightness |
---|---|---|
bright | red | 1 |
“” | orange | 2 |
muted | yellow | 3 |
dull | green | 4 |
teal | 5 | |
blue | ||
violet | ||
grey |
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 sc()
function
Again, these are just hex codes. The above code is the same as writing
sc_blue()
, sc_green()
& friendsEach hue has it’s own helper function. Our last example can be
simplified using sc_blue()
Like sc()
, these helper functions returns hex codes
and in each of these you can adjust the lightness and saturation
sc_across()
You can also go across palettes. Let’s use base R colors again
We could call them with sc()
as
sc("blue", "violet", "red")
but we can also call them with
the first letter of each color using sc_across()
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
For the palettes (sc_green()
, sc_across()
,
etc.), you can get more info about the colors using the
return = ...
argument.
or a table
color_name | hex |
---|---|
pink2 | #F19DF1 |
pink3 | #E444E4 |
pink4 | #9C169C |
pink5 | #590D59 |
At anytime, you can see all of the colors using
show_colors()
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.