Skip to content
Prev 2566 / 63424 Next

Suggestion for qqplot() improvement

(Martin Maechler quoting Werner Stahel, I think)
Would qqplot(qt, y, df=5) or qqplot("t", y, df=5) with the following do
what you want?  As plot warns about surplus arguments, I have removed them
from the ... in its call.

qqplot <- function (x, y, plot.it = TRUE, xlab = deparse(substitute(x)), 
    ylab = deparse(substitute(y)), ...) 
{
    xlab
    sy <- sort(y)
    leny <- length(sy)
    dots <- list(...)
    if(is.character(x)) x <- get(paste("q", x, sep=""))
    if(is.function(x)) {
        fn <- x
        formals(fn) <- c(formals(fn), "..." = list(NULL))
        sx <- fn(ppoints(leny), ...)
        dots <- dots[!match(names(dots), names(formals(x)), FALSE)]
    } else {    
        sx <- sort(x)
        lenx <- length(sx)
        if (leny < lenx) sx <- approx(1:lenx, sx, n = leny)$y
        if (leny > lenx) sy <- approx(1:leny, sy, n = lenx)$y
    }
    if (plot.it) 
        do.call("plot", c(list(sx, sy, xlab = xlab, ylab = ylab), dots))
    invisible(list(x = sx, y = sy))
}