R package colortools

by: Gaston Sanchez

Abstract

The R package colortools is designed to provide some handy tools that allow users generate color schemes and palettes without leaving R.

# remember to install the package first: install.packages('colortools')
library(colortools)

Color Wheel

First things first: the color wheel. The starting point for generating color schemes and combining colors is the so called color wheel. The idea behind the color wheel is to help you choose colors in ways that they look good together. Historically, there have been many variations of the basic design, but the most popular version is a wheel of 12 colors based on the RYB (Red, Yellow, Blue) color model. You can create color wheels by using the function wheel and some given color.

# color wheel for 'tomato'
wheel("tomato")

plot of chunk unnamed-chunk-2

##  [1] "#FF6347" "#FFBF47" "#E3FF47" "#87FF47" "#47FF63" "#47FFBF" "#47E3FF"
##  [8] "#4787FF" "#6347FF" "#BF47FF" "#FF47E3" "#FF4787"

Analogous (Adjacent) Color Scheme

Analogous colors are any three colors which are side by side on a 12 part color wheel, such as yellow-orange, yellow, and yellow-green (usually one of the three colors predominates). Adjacent colors usually provide a harmonious color scheme, creating serene and comfortable designs pleasing to the eye. You can also get an analogous scheme for a given color with the functions analogous and adjacent.

# analogous (adjacent) colors of 'tomato'
analogous("tomato")

plot of chunk unnamed-chunk-3

## [1] "#FF6347" "#FFBF47" "#FF4787"

Complementary (Opposite) Color Scheme

Complementary or opposite colors are just another basic color scheme derived from the color wheel. As its name indicates, opposite colors are colors from the opposite ends of the color wheel, and they provide the most contrast, creating a powerful (or even startling) look. The trick is to arrange them wisely so they don't clash. You can get a complementary scheme for a given color with the functions complementary and opposite.

# complementary (opposite) color of 'tomato'
complementary("tomato")

plot of chunk unnamed-chunk-4

## [1] "#FF6347" "#47E3FF"

Split Complementary Color Scheme

Split complementary colors is a variation of the complementary color scheme that uses two colors on either side of a directly opposite color. These colors have high visual contrast but with less visual tension than purely complementary colors. You can get a split complementary scheme for a given color with the function splitComp.

# split complementary colors of 'tomato'
splitComp("tomato")

plot of chunk unnamed-chunk-5

## [1] "#FF6347" "#47FFBF" "#4787FF"

Triadic Color Scheme

A triadic color scheme uses colors that are evenly spaced around the color wheel. You can get a triadic scheme for a given color with the function triadic.

# triadic colors of 'tomato'
triadic("tomato")

plot of chunk unnamed-chunk-6

## [1] "#FF6347" "#47FF63" "#6347FF"

Tetradic Color Scheme

Tetradic or rectangle colors consist of four colors arranged into two complementary pairs, creating a rich scheme which offers plenty of possibilities for variation. A tetradic scheme for a given color can be generated with the function tetradic.

# tetradic colors of 'tomato'
tetradic("tomato")

plot of chunk unnamed-chunk-7

## [1] "#FF6347" "#E3FF47" "#47E3FF" "#6347FF"

Square Color Scheme

A square color scheme is similar to the tetradic scheme, but with all four colors spaced evenly around the color wheel. You can get square colors for a given color with the function square.

# square colors of 'tomato'
square("tomato")

plot of chunk unnamed-chunk-8

## [1] "#FF6347" "#87FF47" "#47E3FF" "#BF47FF"

Sequential Colors

In addition to the color schemes, colortools also comes with the function sequential that allows to get a sequence of colors from high to low. This is a very flexible function to play with different combinations of saturation, value, and alpha (colors in HSV model)

# sequential colors of 'tomato'
sequential("tomato")

plot of chunk unnamed-chunk-9

##  [1] "#FFFFFFFF" "#FFF4F2FF" "#FFE9E6FF" "#FFDFD9FF" "#FFD4CCFF"
##  [6] "#FFC9BFFF" "#FFBEB3FF" "#FFB3A6FF" "#FFA999FF" "#FF9E8CFF"
## [11] "#FF9380FF" "#FF8873FF" "#FF7D66FF" "#FF7259FF" "#FF684CFF"
## [16] "#FF5D40FF" "#FF5233FF" "#FF4726FF" "#FF3C19FF" "#FF320DFF"
## [21] "#FF2700FF"

A more sophisticated example

# sequential sequence for saturation, with fix value s=0.8, alpha=0.5,
# percentage 10, and fun='log'
sequential("tomato", 10, what = "value", s = 0.7, alpha = 0.5, fun = "log")

plot of chunk unnamed-chunk-10

##  [1] "#00000080" "#180A0780" "#2E130E80" "#431B1480" "#56231A80"
##  [6] "#672A1F80" "#78312480" "#87372980" "#963D2D80" "#A4433180"
## [11] "#B1483580"

Small assorment of color palettes

Another feature of colortools is the function pals that contains an assortment of nice color palettes.

# color palettes
pals()

plot of chunk unnamed-chunk-11

To get the names of the colors from a given palette, we just simple specify its name:

# color names of palette 'cheer'
pals("cheer")
## [1] "#556270" "#4ECDC4" "#C7F464" "#FF6B6B" "#C44D58"

You can also visualize the colors in a 'pizza' wheel

# color names of palette 'cheer'
pizza(pals("cheer"))

plot of chunk unnamed-chunk-13


Visualizing R color palettes

As you can tell, the function pizza is an adaptation of the color wheel, which allows us to generate a pie chart with given colors.

# terrain colors (12)
pizza(terrain.colors(12), bg = "white")

plot of chunk unnamed-chunk-14