colorbar: Draw colorbar on a plot

View source: R/colorbar.R

colorbarR Documentation

Draw colorbar on a plot

Description

The function adds a color bar to plot.

Usage

colorbar(
  colors,
  x,
  y = NULL,
  direction = "vertical",
  height = 1,
  width = 1,
  border = "black",
  lwd = 2,
  lty = 1,
  labs = NULL,
  labs.pos = NULL,
  title = NULL,
  title.pos = NULL,
  ticks = TRUE,
  tck.pos = NULL,
  tck.length = 1,
  xpd = FALSE,
  ...
)

Arguments

colors

vector of colors.

x, y

the x and y coordinates where the bottom left corner of the bar is positioned. Keywords as in legend are allowed.

direction

either "vertical" or "horizontal".

height

a number indicating the amount by which the height of the bar should be scaled relative to the default.

width

a number indicating the amount by which the width of the bar should be scaled relative to the default.

border

color of the border around the bar. Set NA to suppress border drawing.

lwd

border line width.

lty

border line type.

labs

the vector of labels to place next to the bar.

labs.pos

either "left"/"right" for direction="vertical" or "top"/"bottom" for direction="horizontal". Default settings are "right" and "bottom".

title

the title to be placed next to the bar.

title.pos

either on the "top" or at the "bottom" of the bar. Default setting is "top".

ticks

logical indicating whether ticks should be drawn next to each label.

tck.pos

indicates whether ticks should be plotter "in"side or "out"side the bar border.

tck.length

tick lengths

xpd

a value of the par xpd.

...

further arguments passed to the functions text (for labels and title) and segments. All these arguments must be hooked to the element they refer to by indicating: labs.* for labels, title.\* for title, and tck.\* for ticks. See example for further details.

Author(s)

Silvia Castiglione

Examples


rainbow(30)->cols
replicate(4,paste(sample(letters,4),collapse=""))->labs

plot(rnorm(20),rnorm(20))
colorbar(cols,"topleft")

plot(rnorm(20),rnorm(20))
colorbar(cols,"topright",
         height=1.2,width=1.2,lwd=2,
         labs=labs,labs.pos="left",labs.cex=1.3,labs.adj=1,
         title="Colorbar!",title.cex=1.4,title.font=2,title.adj=c(0,0),
         tck.pos="out",tck.lwd=2,xpd=TRUE)

RRphylo documentation built on June 7, 2023, 5:49 p.m.