xy.coords
X,Y Arguments

Description

Converts various types of arguments representing points in two dimensions to a standard form: numeric x and y vectors.

Usage

xy.coords(x, y = NULL, xlab = NULL, ylab = NULL, log = NULL,
    recycle = FALSE)

Arguments

x if y is supplied and is not NULL, a numeric vector or a value that as.numeric(x) can convert to a numeric vector. If y is omitted or NULL, a numeric vector, a matrix, a data.frame, a ts object, or a list containing components named x and y.
y if supplied and not NULL, a numeric vector or something that as.numeric(y) can convert to a numeric vector.
xlab a character string. The output xlab and possibly ylab is based on this string.
ylab a character string. The output ylab can be based on this string.
log A character string: one of "x", "y", or "xy".
  • If log contains an "x", then nonpositive entries in the x component of the output is converted to NA, with a warning.
  • If log contains a "y" the same is done for the y component of the output.
recycle A logical value. If TRUE and the x and y components of the outputs would have different lengths, the shorter is repeated to the length of the longer. If FALSE, the default, an error is given.

Details

If the y argument is omitted or NULL, the x and y components of the output, and the corresponding labels xlab and ylab, are derived from just the x argument, based on its class.
data.frame The first two columns become x and y. Their column names become xlab and ylab. If there is only one column then y is that column, x is seq_along(y), xlab is "Index", and ylab is the input xlab.
list The components named "x" and "y" become x and y and the labels are constructed by pasting the input xlab to "$x" and "$y". It is an error if the list does not contain components named "x" and "y".
matrix The first column becomes x and the second y and the labels come from the names of those columns. If there is only one column it is treated as a vector.
complex The real part of the x argument becomes the output x and the imaginary part becomes y. The labels are "Re(xlab)" and "Im(xlab)".
ts The x component of the output will be time(x) and xlab is "Time" and the y component of the output will be as.numeric(x), with ylab being the input xlab.
vector as.numeric(x) becomes the y component of the output and seq_along(x) becomes the x component. The output xlab will be "Index" and the output ylab will be the input xlab.
In any case, the x and y components of the output will be converted to numeric vectors.
Value
returns a list with four components, the first two representing points in two dimensions.
x a numeric vector giving the x coordinates of the points
y a numeric vector giving the y coordinates of the points
xlab a character string giving a label for the x component
ylab a character string or NULL giving a label for the y component
Examples
xy.coords(41:45, c(81, 83, 87, 91, 97))
xy.coords(ts(41:45, start=2015.75, freq=4))
xy.coords(data.frame(Temp=11:13, NOx=21:23), ylab="The Response")
xy.coords(matrix(11:16, ncol=2, dimnames=list(NULL, c("ColA", "ColB"))))
xy.coords(list(y=11:13, x=21:23, x2=31:33))
xy.coords(exp(1i*seq(0,2*pi,len=5)))
xy.coords(list(x=11:13, y=21:25), recycle=TRUE)
xy.coords(c(1,-2,3), c(-1,2,3), log="xy")
Package grDevices version 6.0.0-69
Package Index