Learn R Programming

itsadug (version 0.8)

gradientLegend: Utility function.

Description

Add a gradient legend to a contour plot (or other plot) to indicate the range of values represented by the color palette.

Usage

gradientLegend(valRange, color = "topo", nCol = 30, pos = 0.5, side = 4,
  length = 0.25, depth = 0.05, inside = TRUE, coords = FALSE,
  n.seg = 3, border.col = "black")

Arguments

valRange
Range of the values that is represented by the color palette. Normally two value-vector. If a larger vector is provided, only the min and max values are being used.
color
Name of color palette to use ('topo', 'terrain', 'heat', 'rainbow'). Custom color palettes can also be provided, but then the argument nCol is ignored.
nCol
Number of colors in the color palette.
pos
A number indicating the position on the axis in proportion. Using the arguments length and depth and side the position of the legend is calculated automatically. Alternatively, one could provide a vector with 4 numb
side
Which axis to choose: 1=bottom, 2=left, 3=top, 4=right. Default is 4.
length
Number, indicating the width of the legend as proportion with respect to the axis indicated by side. Note: when pos is defined by 4 numbers, length is ignored.
depth
Number, indicating the height of the legend as proportion with respect to the axis perpendicular to side. Note: when pos is defined by 4 numbers, depth is ignored.
inside
Logical: whether or not to plot the legend inside or outside the plot area. Note: when pos is defined by 4 numbers, inside is ignored.
coords
Logical: whether or not pos is defined as coordinates. When FALSE, the default, pos is defined in proportions. Note: when pos is defined by 1 number, inside is ignored.
n.seg
Number of ticks and markers on the scale.
border.col
Color of the border and the ticks.

See Also

Other Utility functions for plotting: addInterval; alphaPalette; alpha; dotplot_error; emptyPlot; errorBars; fadeRug; fill_area; find_difference; getCoords; horiz_error; plot_error

Examples

Run this code
data(simdat)
# simple GAM model:
m1 <- bam(Y~te(Time, Trial), data=simdat)

# The functions pvisgam and fvisgam automatically plot legend,
# but vis.gam does not:
vis.gam(m1, view=c("Time", "Trial"), plot.type='contour', color='topo',
zlim=c(-14,14) )
gradientLegend(valRange=c(-14,14),pos=.5, side=3)
gradientLegend(valRange=c(-14,14),pos=.125, side=4, inside=FALSE)
gradientLegend(valRange=c(-14,14),pos=.75, length=.5,
color=alphaPalette('white', f.seq=seq(0,1, by=.1)), border.col='white')
# when defining custom points, it is still important to specify side:
gradientLegend(valRange=c(-14,14), pos=c(500,-5,1250,-4), coords=TRUE,
border.col='red', side=1)

Run the code above in your browser using DataLab