Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: Normal quantile plot #369
    JWaddle
    Member

    Hi Gaddi,

    For changing the axes, use xaxt = “n” or yaxt = “n” in the initial qqnorm call, then construct the axis manually with axis().

    I created a quick function addQQpoints() for plotting additional sets of data to an existing plot (this function is just a slight altering of the qqnorm() function).

    Lastly, for the colors, I used a color palette I created that allows for easy semi-transparent colors, so that you can see the data when there are overlaps. This is of course optional.

    Let me know if this is what you are looking for:

    #install.packages("oaColors", repos = "http://repos.openanalytics.eu", type = "source")
    addQQpoints <- function (y, ylim, main = "Normal Q-Q Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, datax = FALSE, ...) { if (has.na <- any(ina <- is.na(y))) { yN <- y y <- y[!ina] } if (0 == (n <- length(y))) stop("y is empty or has only NAs") if (plot.it && missing(ylim)) ylim <- range(y) x <- qnorm(ppoints(n))[order(order(y))] if (has.na) { y <- x x <- yN x[!ina] <- y y <- yN } if (plot.it) if (datax) plot(y, x, ...) else points(x, y, ...) invisible(if (datax) list(x = y, y = x) else list(x = x, y = y)) } pdf("exampleQQ.pdf", width = 8, height = 8) x1 <- rnorm(100) x2 <- rnorm(100) x3 <- rnorm(100) qqnorm(x1, pch = 19, col = oaColors("orange", alpha = 0.7), yaxt = "n", ylim = c(-3, 3), ylab = "Sample Percentiles") axis(2, at = seq(-3, 3, by = 1), labels = c("0.15%", "2.5%", "16%", "50%", "66%", "97.5%", "99.85%")) qqline(x1) addQQpoints(x2, pch = 19, col = oaColors("blue", alpha = 0.7)) addQQpoints(x3, pch = 19, col = oaColors("green", alpha = 0.7)) dev.off()

    Example graph (http://imgur.com/xanls, apologies about the poor image quality)

    • This reply was modified 12 years, 8 months ago by bryan.
    • This reply was modified 12 years, 8 months ago by bryan.
    • This reply was modified 12 years, 8 months ago by JWaddle.
    • This reply was modified 12 years, 8 months ago by bryan.
Viewing 1 post (of 1 total)
Scroll to top
Privacy Policy