Category Archives: R Colors

R Graphics: Color Ramp Functions

Color ramp functions in R simplify color selection and assignment.  Visual reference examples are provided to illustrate their use and flexibility.

Color Ramp: rainbow()

The rainbow() ramp is is the standard light spectrum with red, green and blue as its base. The functional form is rainbow(n, s=1, v=1, start=0, end=max(1, n-1)/n, alpha=1).  The s and v values correspond to saturation and value from the HCL color scheme (described below).  The parameters start and end can be used to specify particular subranges of hues. The following values can be used when generating such a subrange: red = 0, yellow = 1/6, green = 2/6, cyan = 3/6, blue = 4/6 and magenta =5/6.

Posted in R Colors, R Graphics | Comments Off on R Graphics: Color Ramp Functions

Colors in ggplot

There are number of ways to control the default colors in ggplot.

The HCL Color Wheel

ggplot simplifies color choice with its default color selection, which are based on a “color wheel.”  The result is a well balanced graphic that doesn’t draw too much attention to any one color.  ggplot uses the HCL color wheel and the hue_pal() function from the scales package.  Specifically, if there are two colors, then they will be selected from opposite points on the circle; if there are three colors, they will be 120° apart on the color circle; and so on.  This ensure that discrete data has maximum contrast as a function of the number variables present.

Posted in ggplot2, R Colors | Comments Off on Colors in ggplot

R Graphics: Grey Scales

Grey scales in R can be used effectively in data visualization.  Several simple functions can be used to great effect.

Creating Gray Scales

The gray.colors() function creates a vector of interpolated values that represent evenly-spaced gray colors. 

The function has the form gray.colors(num_colors, start = value, end = value, gamma = value).  End and start define the endpoints of the range of grays, with 0 = black and 1 = white being the extreme values. (By default, start = 0.3 and end = 0.9.) gamma is an optional argument which controls luminance.

Posted in R Colors, R Graphics | Comments Off on R Graphics: Grey Scales

R Graphics: Heat Colors

Heat colors in R utilize basic color ramp  functions.  Simple example scripts with basic control options follow.

Heat Colors

The heat.colors() function creates a ramp of contiguous colors clustered around the color orange in the red spectrum of the RGB scale.  The function has the form heat.colors(num_colors, alpha=value).

Color Ramp Example


Alpha Transparency

Heat color transparency is controlled with the optional alpha argument.  The default value is alpha=1.

Posted in R Colors, R Graphics | Comments Off on R Graphics: Heat Colors

R Color Basics

R Color Basics

R graphical devices support a broad range of colors and color functions.  The colors() command with no input arguments returns a list of all available colors in R.  Presently, there are 657 colors.  In practice, declaring colors can be achieved three ways:

  • character names (e.g. “red”, “orange”, “yellow”),
  • 3-digit RGB values (e.g. 255 0 0265 155 0255 255 0), and
  • hexadecimal strings (e.g. “#FF0000”, “#FFA500”, “#FFFF00”).
Posted in R Colors | Comments Off on R Color Basics

R Color Tables: Download

The following page provides R color tables by name and hexadecimal code. The tables can be downloaded for local reference or recreated with R code provided.

R Color Tables: By Name

A pdf file for the color name table can be downloaded here” R Colors By Name (2320 downloads)

Click to enlarge

Posted in R Colors, R Graphics | 1 Comment

Color Palettes in R

The following list details all color palettes and color ramp functions in R.  Detailed color tables are created for long-term reference and to aide code scripting.  The objective is to simplify the delivery of publication quality graphics.


Posted in R Colors, R Graphics | Comments Off on Color Palettes in R

RColorBrewer Palettes

Color Groups

RColorBrewer is an R packages that uses the work from to help you choose sensible colour schemes for figures in R.  The colors are split into three group, sequential, diverging, and qualitative. 

  • Sequential – Light colours for low data, dark for high data
  • Diverging –  Light colours for mid-range data, low and high contrasting dark colours
  • Qualitative – Colours designed to give maximum visual difference between classes
Posted in R Colors, R Graphics | Comments Off on RColorBrewer Palettes

R Colors By Name

The R color table appears below.  Downloaded here:  R Colors By Name (2320 downloads) .

Posted in R Colors, R Graphics | Comments Off on R Colors By Name