Learn R Programming

units (version 0.4-2)

plot.units: create axis label with appropriate labels

Description

create axis label with appropriate labels

plot unit objects

Usage

make_unit_label(lab, u, sep = get(".units.sep", envir = .units_options), group = get(".units.group", envir = .units_options), parse = get(".units.parse", envir = .units_options))
"plot"(x, y, xlab = NULL, ylab = NULL, ...)

Arguments

lab
length one character; name of the variable to plot
u
vector of class units
sep
length two character vector, defaulting to c("~","~"), with the white space between unit name and unit symbols, and between subsequent symbols.
group
length two character vector with grouping symbols, e.g. c("(",")") for parenthesis, or c("","") for no group symbols
parse
logical; indicates whether a parseable expression should be returned (typically needed for super scripts), or a simple character string without special formatting.
x
object of class units, to plot along the x axis, or, if y is missing, along the y axis
y
object to plot along the y axis, or missing
xlab
character; x axis label
ylab
character; y axis label
...
other parameters, passed on to plot.default

Details

units_options can be used to set and change the defaults for sep, group and doParse.

Examples

Run this code
oldpar = par(mar = par("mar") + c(0, .3, 0, 0))
displacement = mtcars$disp * ud_units[["in"]]^3
# an example that would break if parse were (default) TRUE, since 'in' is a reserved word:
units_options(parse=FALSE)
make_unit_label("displacement", displacement)
units_options(parse=TRUE)
units(displacement) = with(ud_units, cm^3)
weight = mtcars$wt * 1000 * with(ud_units, lb)
units(weight) = with(ud_units, kg)
plot(weight, displacement)
units_options(group = c("(", ")") )  # parenthesis instead of square brackets
plot(weight, displacement)
units_options(sep = c("~~~", "~"), group = c("", ""))  # no brackets; extra space
plot(weight, displacement)
units_options(sep = c("~", "~~"), group = c("[", "]"))
gallon = make_unit("gallon")
consumption = mtcars$mpg * with(ud_units, mi/gallon)
units(consumption) = with(ud_units, km/l)
plot(displacement, consumption) # division in consumption
units_options(negative_power = TRUE) # division becomes ^-1
plot(displacement, consumption)
plot(1/displacement, 1/consumption)
par(oldpar)

Run the code above in your browser using DataLab