sl.num2colbar: Convert Numerics to Integers Corresponding to Colourbar...

sl.num2colbarR Documentation

Convert Numerics to Integers Corresponding to Colourbar Breaks

Description

Convert a numerical vector or array to integers corresponding to discrete intervals defined by colourbar breaks. If the latter are not provided (as argument breaks or as an element of colbar named 'breaks'), they are computed by calling sl.num2colbarbreaks). This function is used by various plotting functions.

Usage

sl.num2colbar(num, colbar = NULL, breaks = NA, breaks.log = FALSE)

Arguments

num

a numerical scalar, vector, or array that shall be mapped to colourbar breaks

colbar

a spheRlab colourbar of length N (as returned by sl.colbar), or a list including such a colourbar as an element named 'colbar'. In the latter case, if colbar also includes an element named 'breaks', the argument breaks is ignored and taken from colbar. If breaks are provided, this argument is optional.

breaks

a vector of length N-1 specifying the breaks corresponding to colbar. Ignored if colbar is a list with elements 'colbar' as well as 'breaks'.

breaks.log

a logical value indicating whether the breaks shall be placed in logarithmic steps. Default is breaks.log=FALSE. Only used if breaks is not provided, neither directly nor as part of colbar.

Details

This function is used by sl.num2colbarbreaks, sl.plot.elem, sl.plot.field, and sl.plot.fld.curvilin.

Value

colour.index

A vector or array with the same dimensions as the argument num, converted to integers corresponding to discrete intervals defined by breaks (which were either provided as argument or computed by calling sl.num2colbarbreaks).

breaks

A vector giving the breaks (particularly relevant if these were not provided as argument but computed by calling sl.num2colbarbreaks).

Author(s)

Helge Goessling

See Also

sl.colbar, sl.num2colbarbreaks.

Examples

cb = sl.colbar(cols=list(c(1,0,0),c(.5,.5,.5),c(0,0,1)),N=5)
num = runif(n=100,min=-5,max=5)
cb_breaks = sl.num2colbarbreaks(num=num,colbar=cb)
sl.num2colbar(num=num,colbar=cb)
## Should return something like (result subject to randomness)
## $colour.index
## [1] 1 5 4 4 1 2 2 2 2 3 1 2 4 5 2 1 1 4 2 1 1 2 4 4 3 4 2 3 5 1 3 4 5 2 5 5 1 2 2
## [40] 5 1 2 3 4 3 1 4 4 2 1 5 1 5 4 2 1 2 2 3 3 2 4 4 4 2 2 3 1 1 4 4 3 2 1 5 2 3 1
## [79] 2 3 1 5 2 3 3 4 4 4 5 3 2 3 4 2 3 5 2 4 3 1
## 
## $breaks
## [1] -2.9800799 -0.9964841  0.9871118  2.9707076

FESOM/spheRlab documentation built on April 6, 2024, 6:52 p.m.