Learn R Programming

oce (version 1.8-3)

labelWithUnit: Create Label With Unit

Description

labelWithUnit creates a label with a unit, for graphical display, e.g. by plot,section-method. The unit is enclosed in square brackets, although setting options(oceUnitBracket="(") will cause parentheses to be used, instead. This function is intended mainly for use within the package, and users should not rely on its behaviour being unchangeable.

Usage

labelWithUnit(name, unit = NULL)

Value

labelWithUnit returns a language object, created with bquote(), that that may supplied as a text string to legend(), mtext(), text(), etc.

Arguments

name

character value naming a quantity.

unit

a list containing items unit and (optionally) scale, only the first of which, an expression(), is used. If unit is not provided, then a default will be used (see “Details”).

Author

Dan Kelley

Details

If name is in a standard list, then alterations are made as appropriate, e.g. "SA" or "Absolute Salinity" yields an S with subscript A; "CT" or "Conservative Temperature" yields an upper-case Theta, sigmaTheta yields a sigma with subscript theta, sigma0 yields sigma with subscript 0 (with similar for 1 through 4), "N2" yields "N" with superscript 2, and "pressure" yields "p". These basic hydrographic quantities have default units that will be used if unit is not supplied (see “Examples”).

In addition to the above, several chemical names are recognized, but no unit is guessed for them, because the oceanographic community lacks agreed-upon standards.

If name is not recognized, then it is simply repeated in the return value.

See Also

Other functions that create labels: resizableLabel()

Examples

Run this code
library(oce)
# 1. temperature has a predefined unit, but this can be overruled
labelWithUnit("temperature")
labelWithUnit(
    "temperature",
    list(unit = expression(m / s), scale = "erroneous")
)
# 2. phosphate lacks a predefined unit
labelWithUnit("phosphate")
data(section)
labelWithUnit(
    "phosphate",
    section[["station", 1]][["phosphateUnit"]]
)

Run the code above in your browser using DataLab