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.
#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"))
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(SDMTools)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/SDMTools/legend.gradient.Rd_%03d_medium.png", width=480, height=480)
> ### Name: legend.gradient
> ### Title: Legend Gradient
> ### Aliases: legend.gradient
>
> ### ** Examples
>
> #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"))
>
>
>
>
>
> dev.off()
null device
1
>