colPointsLegend {berryFunctions}R Documentation

Legend for colPoints

Description

Adds legends to plots created or enhanced with colPoints.
sf plots set par(mar=c(0,0,1.2,0)) but then reset it to the values before. smallPlot will hence also reset to that, so points added after calling colpointsLegend will be wrong, unless the margins are set BEFORE sf plot. sf:::plot.sf alternatively uses c(2.1, 2.1, 1.2, 0) or c(1, 1, 1.2, 1).

Usage

colPointsLegend(
  z,
  Range = range(z, finite = TRUE),
  nbins = 100,
  colors = seqPal(nbins),
  bb = seqR(Range, length.out = nbins + 1),
  nlab = 5,
  at = pretty2(Range, nlab),
  labels = at,
  atgrey = NULL,
  adj = 0.5,
  x1 = 0.6,
  y1 = 0.88,
  x2 = 0.99,
  y2 = 0.99,
  outer = FALSE,
  xpd = NA,
  mar,
  mgp = c(1.8, 0.6, 0),
  bg = par("bg"),
  sborder = NA,
  resetfocus = TRUE,
  plottriangle = FALSE,
  triangle = 0.14,
  tricol = c(8, 1),
  density = NULL,
  lines = TRUE,
  atminmax = FALSE,
  horizontal = TRUE,
  labelpos = 1,
  titlepos = 3,
  title = "Legend",
  las = 1,
  x,
  y,
  index,
  above,
  below,
  ...
)

Arguments

z

Values of third dimension used in colPoints, can be a matrix or a vector etc, but must be numeric

Range

Ends of color bar for method=equalinterval. DEFAULT: range(z, finite=TRUE)

nbins

Number of classes (thus, colors). If colors is given, nbins is overwritten with length(colors). DEFAULT: 100

colors

Color vector. DEFAULT: seqPal from yellow (lowest) to blue (highest value in Range)

bb

Borders of bins for the legend (key). DEFAULT: seqR(Range, length.out=nbins+1)

nlab, at, labels

Number of legend labels, their positions and labels. DEFAULT: nlab=5, labels=at=pretty2(Range,nlab)

atgrey

Positions for grey lines with no label, if given. DEFAULT: NULL

adj

label adjustment parallel to legend bar (only one number!). DEFAULT: 0.5

x1, x2, y1, y2

Relative coordinates [0:1] of inset plot, see smallPlot. DEFAULT: x: 0.6-0.99, y: 0.88-0.99

outer

Logical: Should legend be relative to device instead of current figure? use outer=TRUE when par(mfrow, oma) is set. DEFAULT: FALSE

xpd

Logical: should text be expanded outside of plotting region? Must be NA if outer=TRUE. DEFAULT: NA

mar

Margins for smallPlot. 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)

bg

Background behind key, labels and title. DEFAULT: par("bg")

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? Vector of length two (for lower and upper, internally recycled). If this argument is missing but triangle is given, this is set to TRUE. 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(8,1)

density

List of arguments passed to kernel density estimation. Can also be FALSE to suppress KDE line drawing. 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

x, y, index, above, below

Ignored arguments, so that you can pass the result from colPoints via do.call(colPointsLegend, cp_result)

...

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

Note

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

Author(s)

Berry Boessenkool, berry-b@gmx.de, 2012-2014

See Also

colPointsHist, colPoints for real life example

Examples


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=0.05, x2=0.3, y1=0.7,y2=0.9, title="Booh!", density=FALSE)
# Denote values outside of Range wit a triangle:
colPointsLegend(z=z, Range=c(-1,3), x1=0.2, y1=0.4, y2=0.6, triangle=0.2)
colPointsLegend(z=z, horiz=FALSE, x1=0.7, y1=0.6, plottriangle=TRUE, density=FALSE)
?colPoints # example section for actual usage


[Package berryFunctions version 1.22.5 Index]