LabelAxis: Axis label expression

View source: R/LabelAxis.R

LabelAxisR Documentation

Axis label expression

Description

Obtain an axis label involving common math expressions for label and units.

Usage

LabelAxis(
  label = "oxy",
  prefix = "",
  suffix = "",
  unit = "permil",
  time.unit = NULL,
  unit.type = "standard",
  bracket.type = "round",
  dot = FALSE,
  font = 1
)

Arguments

label

character string with the name of the quantity referred to on the axis; see details for the available keywords to automatically produce common math expressions of axis names.

prefix

optional character string preceding the axis label with an empty space automatically being inserted between them.

suffix

optional character string following the axis label with an empty space automatically being inserted between them.

unit

character string with an abbreviation of the physical unit of the quantity displayed on the axis; see details for the available keywords to automatically produce common math expressions of units. The unit is placed after the label, with an empty space inserted between them and surrounded by brackets as specified in bracket.type.

time.unit

character string with an abbreviation of the physical unit of time needed to determine the unit of power spectral density when axis.type == "psd"; see the examples.

unit.type

character; the type of axis for determining the format of the axis unit. Default "standard" means to use the unit as is; other possible options are frequency axis, "freq", trend axis, "trend", and power spectral density axis, "psd". For a frequency axis, the passed unit is displayed to the power of -1; for a trend axis, the passed unit is multiplied by the unit of time given in time.unit to the power of -1; and for a power spectral density axis, the unit is displayed to the power of 2 multiplied by the unit of time given in time.unit; see the examples.

bracket.type

the type of bracket to use for surrounding the unit; possible options are "round" brackets (default), "square" brackets, or "curly" {.} brackets.

dot

logical; shall a multiplication sign (as a dot) be placed between the units for axis types "trend" and "psd"? Defaults to FALSE.

font

an integer which specifies which font to use for the label text; see ?par for the available options. Note that the font setting has no effect on greek and other symbols.

Details

This function provides some keywords to automatically format common math expressions for axis labels and units.

For label:

"oxy":

notation for oxygen isotopic composition; i.e., a greek delta followed by a roman "O" prefixed by superscript "18".

"dtr":

notation for hydrogen isotopic composition; i.e., a greek delta followed by a roman "H" prefixed by superscript "2".

"dtr.var":

alternative notation for hydrogen isotopic composition: greek delta followed by a roman "D".

For unit:

"percent":

the percent sign.

"permil":

the per mille sign.

"celsius":

degree Celsius.

Value

a language object to be passed on to xlab, ylab etc. parameter settings in plot calls, or directly to text or mtext calls.

Author(s)

Thomas Münch

Examples


plot(1 : 15, type = "n", xlab = "", ylab = "")

# preformatted isotope labels and units using the keywords
text(1, 15, adj = 0, labels = LabelAxis(label = "oxy"))
text(1, 14, adj = 0, labels = LabelAxis(label = "dtr"))
# change font setting
# (but note that greek letters and other symbols remain unchanged)
text(1, 13, adj = 0, labels = LabelAxis(label = "dtr.var", font = 2))

# use normal text as label
text(1, 12, adj = 0, labels = LabelAxis(label = "Some other isotope species"))

# use a prefix together with a preformatted label
text(1, 11, adj = 0, labels = LabelAxis(label = "oxy", prefix = "Ice core"))

# use a suffix together with a preformatted label
text(1, 10, adj = 0, labels = LabelAxis(label = "oxy", suffix = "anomaly"))

# use both
text(1, 9, adj = 0, labels = LabelAxis(label = "oxy",
     prefix = "Ice core", suffix = "anomaly"))

# temperature unit in degree Celsius
text(1, 8, adj = 0,
     labels =  LabelAxis(label = "Temperature", unit = "celsius"))

# automatic formatting of unit for a frequency axis
text(1, 7, adj = 0,
     labels = LabelAxis(label = "Frequency", unit = "yr",
                        unit.type = "freq"))

# automatic formatting of unit for a trend axis
text(1, 6, adj = 0,
     labels = LabelAxis(label = "Temperature trend", unit = "celsius",
                        time.unit = "yr", unit.type = "trend"))

# automatic formatting of unit for a power spectral density axis
text(1, 5, adj = 0,
     labels = LabelAxis(label = "PSD", unit = "permil",
                        time.unit = "yr", unit.type = "psd"))
# use a multiplication dot
text(1, 4, adj = 0,
     labels = LabelAxis(label = "PSD", unit = "K",
                        time.unit = "s", unit.type = "psd", dot = TRUE))

# note that for the previous examples two units are mandatory:
## Not run: 
  LabelAxis(label = "trend", unit = "permil", unit.type = "trend")
  LabelAxis(label = "PSD", unit = "permil", unit.type = "psd")

## End(Not run)

# pass preformatted math expression as label (needs to use 'bquote'!)
text(1, 3, adj = 0,
     labels = LabelAxis(label = bquote("T"["2m"]), unit = "celsius"))

# use other brackets around units
text(1, 2, adj = 0,
     labels = LabelAxis(label = "I like squares", unit = "unit",
                        bracket.type = "square"))
text(1, 1, adj = 0,
     labels = LabelAxis(label = "I like curly hair", unit = "unit",
                        bracket.type = "curly"))


EarthSystemDiagnostics/grfxtools documentation built on Aug. 5, 2023, 1:43 p.m.