Learn R Programming

berryFunctions (version 1.5.2)

colPointsLegend: Legend for colPoints

Description

Adds legends to plots created or enhanced with colPoints

Usage

colPointsLegend(z, Range=range(z, finite=TRUE), nbins=40,
colors=rev(rainbow(nbins, start=0, end=.7, alpha=1)),
bb=seqR(Range, length.out=nbins+1), at=pretty2(Range), labels=at, bg="white",
x1=60, y1=99, x2=x1+38, y2=y1-11, mar, mgp=c(1.8, 0.6, 0), sborder=NA,
resetfocus=TRUE, density=NULL, lines=TRUE, atminmax=FALSE, horizontal=TRUE,
labelpos=1, titlepos=3, title="Legend", las=1, ...)

Arguments

z
Values of third dimension used in colPoints, can be matrix, vector, etc, but must be numeric
Range
Ends of color bar. DEFAULT: range(z, finite=TRUE)
nbins
Number of classes (thus, colors). DEFAULT: 40
colors
Color vector. DEFAULT: rainbow from blue (lowest) to red (highest value in Range)
bb
Borders of bins for the legend (key). DEFAULT: seqR(Range, length.out=nbins+1)
at
Positions of legend labels. DEFAULT: pretty2(Range)
labels
Labels that are written at the positions of at. DEFAULT: at
bg
Background behind key, labels and title. DEFAULT: "white"
x1,y1
Topleft relative coordinates (0:100) of inset plot, see smallPlot. DEFAULT: 60,99
x2,y2
Bottomright -"-. DEFAULT: 98,88
mar
Margins for smallPlot in relative values (0:100). DEFAULT: internal calculations based on title, labelpos and titlepos.
mgp
MarGinPlacement: distance of xlab/ylab, numbers and line from plot margin, as in par, but with different defaults. DEFAULT: c(1.8, 0.6, 0)
sborder
Border around inset subplot. DEFAULT: NA
resetfocus
Reset focus to original plot? Specifies where further low level plot commands are directed to. DEFAULT: TRUE
density
Plot kernel density line? arguments passed to density. DEFAULT: NULL
lines
Plot black lines in the color bar at at? DEFAULT: TRUE
atminmax
Should the extrema of the legend be added to at? DEFAULT: FALSE
horizontal
Horizontal bar? if FALSE, a vertical bar is drawn. DEFAULT: TRUE
labelpos
Position of labels relative to the bar. Possible: 1 (below), 2 (left), 3 (above), 4 (right), 5(on top of bar). DEFAULT: 1
titlepos
Position of title -"-. DEFAULT: 3
title
Legend title. DEFAULT: "Legend"
las
LabelAxisStyle. DEFAULT: 1
...
Further arguments passed to text and strwidth, e.g. cex, srt, font, col. But NOT adj!

Value

  • invisible list of par of smallPlot, adds legend bar to current plot

Details

x1,x2,y1,y2,labelpos,titlepos,title have different defaults when horizontal=FALSE.

See Also

colPoints (section examples) for real life example

Examples

Run this code
z <- rnorm(50)
plot(1:10)
colPointsLegend(z=z)
colPointsLegend(z=z, titlepos=2)
colPointsLegend(z=z, horiz=FALSE) # note the different defaults

Run the code above in your browser using DataLab