Learn R Programming

berryFunctions (version 1.7.1)

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=rainbow2(nbins), 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, plottriangle=FALSE, triangle=0.14, tricol=c(1,8),
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
plottriangle
Should triangles be plotted at the end of the legend for values outside Range? TRUE if missing but triangle is given. DEFAULT: FALSE
triangle
Percentage of bar length at lower and upper end for triangles (can be a vector with two different values). DEFAULT: 0.14
tricol
Triangle colors for lower and upper end. DEFAULT: c(1,8)
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
# positioning relative to plot:
colPointsLegend(z=z, x1=5, x2=30, y1=90, y2=70, title="Booh!", density=FALSE)
# Denote values outside of Range wit a triangle:
colPointsLegend(z=z, Range=c(-1,3), x1=20, y1=60, y2=40, triangle=c(0,0.5))
colPointsLegend(z=z, horiz=FALSE, x1=70, y1=60, plottriangle=TRUE, density=FALSE)
?colPoints # example section for actual usage

Run the code above in your browser using DataLab