colmapLegend: Draw legend for a color gradient map

View source: R/yogitools.R

colmapLegendR Documentation

Draw legend for a color gradient map

Description

Draws a legend for a color gradient map created by <code>colmap()</code>.

Usage

colmapLegend(
  cm,
  label,
  corner = "topleft",
  size = c(0.3, 0.15),
  res = 20,
  marginSize = 0.2
)

Arguments

cm

the colmap object created by colmap()

label

the label for the legend

corner

a plot corner described as "top" "topleft","bottomright", etc. in which the legend will be drawn. Defaults to "topleft"

size

a vector of relative width and height of the legend relative to size of the plotting area. Defaults to c(0.3,0.15)

res

resolution of the gradient

marginSize

size of the legend margin relative to its width. Default 0.2.

Examples

#create colmap object
cm <- colmap(c(0,1,2),c("royalblue3","yellow","firebrick3"),naCol="gray")
#create some fake data
data <- data.frame(x=rnorm(1000,2,4), y=rnorm(1000,1,5), z=cm(rnorm(1000,1,1)))
#plot the data
with(data, plot(x,y, col=z))
#draw the legend
colmapLegend(cm,"z",corner="topright")

jweile/yogitools documentation built on May 11, 2023, 7:42 p.m.