hkey: Add a color key to a plot

View source: R/squash.R

hkeyR Documentation

Add a color key to a plot

Description

Add a horizontal or vertical color key to a plot

Usage

hkey(map, title = NA, side = 1, stretch = 1.4, x, y, skip, wh, 
     cex.title = 1, font.title = 1)
vkey(map, title = NA, side = 2, stretch = 1.4, x, y, skip, wh, 
     cex.title = 1, font.title = 1)

Arguments

map

A list, as generated by makecmap.

title

Title for the key.

side

Where to place the labels. (1 or 3 for hkey, 2 or 4 for vkey)

stretch

Aspect ratio of the color rectangles.

x, y

Position of lower left corner of the color rectangles. If missing, the key will be placed automatically in the lower-left (hkey) or lower-right (vkey) corner of the figure region.

skip

Omit every skip labels (optional).

wh

Integer indices indicating which labels to include (optional).

cex.title

Text size multiplier for the key title.

font.title

Font for the key title.

Details

This functions tries to label as many breakpoints as possible, but if the labels would overlap a subset of labels is chosen automatically. If this doesn't look right, the subset of labels can be specified with either skip or wh.

Clipping is turned off, so the key can be placed anywhere in the figure region, including the margins.

Examples

 

  attach(iris)
  map <- makecmap(Petal.Length)
  pl.color <- cmap(Petal.Length, map = map)

  plot(Sepal.Length, Sepal.Width, col = pl.color, pch = 16)
  hkey(map, title = "Petal length (hkey default)")
  hkey(map, title = "Another hkey", x = 3.8, y = 4.7, stretch = 3)

  ## looks bad with default margins
  vkey(map, title = "vkey default")

  vkey(map, title = "Small vkey", x = 7.8, y = 4, stretch = 0.3)


aroneklund/squash documentation built on June 3, 2023, 11:55 a.m.