https://github.com/cran/pracma
Tip revision: 708a2ad382a163d1eef5af0665e3ae2aad200ced authored by HwB on 21 March 2013, 00:00:00 UTC
version 1.4.5
version 1.4.5
Tip revision: 708a2ad
pltcross.R
pltcross <- function(x, y, cx = 0, cy = 0, clen = 0.1,
cent = FALSE, color = "darkgrey", ...) {
stopifnot(is.numeric(x), is.numeric(y),
is.numeric(cx), is.numeric(cy), is.numeric(clen))
if (length(cx) != length(cy))
stop("Length of arguments 'cx', 'cy' must be the same.")
if (length(clen) < length(cx)) {
m <- length(cx); n <- length(clen)
clen <- c(rep(clen, m %/% n), clen[1:(m %% n)])
}
if (length(color) < length(cx)) {
m <- length(cx); n <- length(color)
color <- c(rep(color, m %/% n), color[1:(m %% n)])
}
if (any(clen <= 0 || clen > 1)) {
clen <- ifelse(clen > 0 && clen <= 1, clen, 1)
warning("Proportional length 'clen' should be between 0 and 1.")
}
clx <- (max(x) - min(x)) * clen / 2
cly <- (max(y) - min(y)) * clen / 2
for (i in 1:length(cx)) {
lines(c(cx[i]-clx[i], cx[i]+clx[i]), c(cy[i], cy[i]), col = color[i], ...)
lines(c(cx[i], cx[i]), c(cy[i]-cly[i], cy[i]+cly[i]), col = color[i], ...)
}
if (cent)
points(cx, cx, col = color)
invisible(NULL)
}