Introduction
Choosing colors for a graphic is a bit like taking a trip down the rabbit hole,
that is, it can take much longer than expected and be both fun and frustrating at the same time.
Striking a balance between colors that look good to you and your audience is important.
Keep in mind that color blindness
affects many individuals throughout the world and it is incumbent on you
to choose a color scheme that works in color-blind vision.
Luckily there are a number of excellent R packages
that address this very issue, such as the
colorspace,
RColorBrewer, and
viridis packages.
And because this is R, where diversity is king,
why not offer one more function for creating color blind friendly palettes.
Let me introduce the GetTolColors function in the R-package
inlmisc.
This function generates a vector of colors from qualitative, diverging,
and sequential color schemes by Paul Tol (2018).
The original inspiration for developing this function came from
Peter Carl’s blog post
describing color schemes from an older issue of Paul Tol’s Technical Note (issue 2.2, released Dec. 2012).
And the qualitative color schemes described in his blog post found their way into the
ptol_pal function in the R-package ggthemes.
My intent with this document is to exhibit the latest Tol color schemes (issue 3.0, released May 2018) and show
that they are not only visually pleasing but also well thought out.
To get started, install the inlmisc package from CRAN using the command:
if (system.file(package = &quot;inlmisc&quot;, lib.loc = .libPaths()) == &quot;&quot;)
utils::install.packages(&quot;inlmisc&quot;, dependencies = TRUE)
And if you’re so inclined, read through the function documentation.
utils::help(&quot;GetTolColors&quot;, package = &quot;inlmisc&quot;)
Like almost every other R function used to create a color palette,
GetTolColors takes as its first argument the number of colors to be in the returned palette (n).
For example, the following command generates a palette of 10 colors using default values for function arguments.
cols