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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/colorlegend.R
\name{colorlegend}
\alias{colorlegend}
\title{Draw color legend.}
\usage{
colorlegend(
colbar,
labels,
at = NULL,
xlim = c(0, 1),
ylim = c(0, 1),
vertical = TRUE,
ratio.colbar = 0.4,
lim.segment = "auto",
align = c("c", "l", "r"),
addlabels = TRUE,
...
)
}
\arguments{
\item{colbar}{Vector, color of colbar.}
\item{labels}{Vector, numeric or character to be written.}
\item{at}{Numeric vector (quantile), the position to put labels. See examples
for details.}
\item{xlim}{See in \code{\link{plot}}}
\item{ylim}{See in \code{\link{plot}}}
\item{vertical}{Logical, whether the colorlegend is vertical or horizon.}
\item{ratio.colbar}{The width ratio of colorbar to the total colorlegend
(including colorbar, segments and labels).}
\item{lim.segment}{Vector (quantile) of length 2, the elements should be in
[0,1], giving segments coordinates ranges. If the value is NULL or 'auto',
then the ranges are derived automatically.}
\item{align}{Character, alignment type of labels, \code{'l'} means left,
\code{'c'} means center and \code{'r'} right.
Only valid when \code{vertical} is \code{TRUE}.}
\item{addlabels}{Logical, whether add text label or not.}
\item{\dots}{Additional arguments, passed to \code{\link{plot}}}
}
\description{
Draw color legend.
}
\examples{
## diverging colors
par(mar = c(0, 0, 0, 0) + 0.1)
plot(0, xlim = c(-0.1, 1), ylim = c(0, 1), type = 'n')
col = c('RdBu', 'BrBG', 'PiYG', 'PRGn', 'PuOr', 'RdYlBu')
for(i in 1:length(col)) {
colorlegend(COL2(col[i]), -10:10/10, align = 'l', cex = 0.8, xlim = c(0, 1),
ylim = c(i/length(col)-0.1, i/length(col)), vertical = FALSE)
text(-0.01, i/length(col)-0.02, col[i], adj = 0.5, pos = 2, cex = 0.8)
}
## sequential colors
par(mar = c(0, 0, 0, 0) + 0.1)
plot(0, xlim = c(-0.1, 1), ylim = c(0, 1), type = 'n')
col = c('Oranges', 'Purples', 'Reds', 'Blues', 'Greens', 'Greys', 'OrRd',
'YlOrRd', 'YlOrBr', 'YlGn')
for(i in 1:length(col)) {
colorlegend(COL1(col[i]), 0:10, align = 'l', cex = 0.8, xlim = c(0, 1),
ylim = c(i/length(col)-0.1, i/length(col)), vertical = FALSE)
text(-0.01, i/length(col)-0.02, col[i], adj = 0.5, pos = 2)
}
## other examples to show colorlegend function
par(mar = rep(0, 4))
plot(0, xlim = c(0, 6), ylim = c(-0.5, 1.2), type = 'n')
colorlegend(rainbow(100), 0:9)
colorlegend(heat.colors(100), LETTERS[1:12], xlim = c(1, 2))
colorlegend(terrain.colors(100), 0:9, ratio.colbar = 0.6,
lim.segment = c(0, 0.6), xlim = c(2, 3), align = 'l')
colorlegend(topo.colors(100), 0:9, lim.segment = c(0, 0.6),
xlim = c(3, 4), align = 'l', offset = 0)
colorlegend(cm.colors(100), 1:5, xlim = c(4, 5))
colorlegend(sample(rainbow(12)), labels = LETTERS[1:12],
at = seq(0.05, 0.95, len = 12), xlim = c(5, 6), align = 'r')
colorlegend(colbar = grey(1:100 / 100), 1:10, col = 'red', align = 'l',
xlim = c(0, 6), ylim = c(-0.5, -0.1), vertical = FALSE)
colorlegend(sample(rainbow(12)),
labels = LETTERS[1:12], at = seq(0.05, 0.95, len = 12),
xlim = c(0, 6), ylim = c(1.1, 1.2), vertical = FALSE)
}
\author{
Taiyun Wei
}
\keyword{hplot}
|