Line <- function(x,y) { # x, y are vectors of length 2 # computes equation of line passing through two points (x[i],y[i]) # B <- (y[2]-y[1])/(x[2]-x[1]) A <- y[1] - B*x[1] c(A,B) } QQline <- function(x,y,...){ Y <- quantile(y[!is.na(y)], c(0.25, 0.75)) X <- quantile(x[!is.na(x)], c(0.25, 0.75)) abline(Line(X,Y),...) }