legend.gradient: Legend Gradient

Description Usage Arguments Value Author(s) Examples

View source: R/legend.gradient.r

Description

legend.gradient creates and displays a gradient legend on a plot or image file. The place and size of the legend is defined by coordinates, previously identified.

Usage

1
2
legend.gradient(pnts, cols = heat.colors(100), limits = c(0, 1),
  title = "Legend", ...)

Arguments

pnts

x and y coordinates of the gradient location in the plot

cols

a set of 2 or more colors used in the image, to create the gradient

limits

to label the min and max values of the gradient in the legend

title

to specify the title of the legend

...

other graphical parameters defined by image() or plot()

Value

nothing is returned, a gradient legend is added to a plot or a image.

Author(s)

Lorena Falconi lorefalconi@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#define a simple binary matrix
tmat = { matrix(c( 0,0,0,1,0,0,1,1,0,1,
                   0,0,1,0,1,0,0,0,0,0,
                   0,1,NA,1,0,1,0,0,0,1,
                   1,0,1,1,1,0,1,0,0,1,
                   0,1,0,1,0,1,0,0,0,1,
                   0,0,1,0,1,0,0,1,1,0,
                   1,0,0,1,0,0,1,0,0,0,
                   0,1,0,0,0,1,0,NA,NA,NA,
                   0,0,1,1,1,0,0,NA,NA,NA,
                   1,1,1,0,0,0,0,NA,NA,NA),nr=10,byrow=TRUE) }

#do the connected component labeling
tasc = ConnCompLabel(tmat)

# Create a color ramp
colormap=c("grey","yellow","yellowgreen","olivedrab1","lightblue4")

#create an image
image(tasc,col=colormap, axes=FALSE, xlab="", ylab="", ann=FALSE)

#points for the gradient legend
pnts = cbind(x =c(0.8,0.9,0.9,0.8), y =c(1.0,1.0,0.8,0.8))

#create the gradient legend
legend.gradient(pnts,colormap,c("Low","High"))

Example output



SDMTools documentation built on Jan. 11, 2020, 9:23 a.m.