colorBar: Add a color bar

Description Usage Arguments Details Author(s) References See Also Examples

View source: R/colorBar.R

Description

This function produces a color bar.

Usage

1
2
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.

Author(s)

Tsung Fei Khang tfkhang@um.edu.my

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#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)

Example output

sh: 1: cannot create /dev/null: Permission denied
sh: 1: cannot create /dev/null: Permission denied
Warning messages:
1: In rgl.init(initValue, onlyNULL) : RGL: unable to open X11 display
2: 'rgl_init' failed, running with rgl.useNULL = TRUE 
3: .onUnload failed in unloadNamespace() for 'rgl', details:
  call: fun(...)
  error: object 'rgl_quit' not found 

monogeneaGM documentation built on May 29, 2017, 9:18 p.m.