Learn R Programming

monogeneaGM (version 1.1)

colorBar: Add a color bar

Description

This function produces a color bar.

Usage

colorBar(colpalette = NULL, min, max = -min, nticks = 11, ticks = seq(min, max, len = nticks), tit = "")

Arguments

colpalette
a color palette supplied by the user; defaults to the red-white-blue palette if left undefined
min
the smallest numeric value corresponding to the color on the extreme left of the color palette
max
the largest numeric value corresponding to the color on the extreme right of the color palette
nticks
number of tick lines on the color bar
ticks
spacing for the tick marks on the color bar
tit
title for the color bar

Details

This R code is a based on John Colby's (2011) color.bar code. A user-defined color palette can be generated using the colorRampPalette function. See www.colorbrewer2.org for interesting color palette options.

References

Colby J. (2011). Color bar legends for neuroimaging in R. Available at http://www.colbyimaging.com/wiki/statistics/color-bars.

Khang TF, Soo OYM, Tan WB, Lim LHS. (2016). Monogenean anchor morphometry: systematic value, phylogenetic signal, and evolution. PeerJ 4:e1668.

See Also

pcloadhm, colorRampPalette

Examples

Run this code
#define a color scale
tones <- c("#99000D", "#FB6A4A", "white", "#6BAED6", "#084594")
multihue <- colorRampPalette(tones, space = "Lab")(101)

#create a two-panel figure with width ratio of 4:1
nf <- layout(matrix(c(1,1,1,1,2),2,5,byrow=TRUE))
layout.show(nf)

#mapping a matrix of randomly chosen numbers between -1 and 1 to
#colors in the color scale
h <- matrix(runif(100, -1, 1),10,10)
image(h,col=multihue,xaxt="n", yaxt="n")

#add color bar
par(mar=c(5,5,5,2))
colorBar(colpalette=multihue, min=-1,max=1)

Run the code above in your browser using DataLab