Created
April 5, 2013 19:22
-
-
Save stephenturner/5321887 to your computer and use it in GitHub Desktop.
create qq plot where you can specify the upper limit on the y-axis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
qq = function(pvector, ymax=NA, ...) { | |
if (!is.numeric(pvector)) stop("D'oh! P value vector is not numeric.") | |
pvector <- pvector[!is.na(pvector) & pvector<1 & pvector>0] | |
o = -log10(sort(pvector,decreasing=F)) | |
e = -log10( ppoints(length(pvector) )) | |
if (!is.numeric(ymax) | ymax<max(o)) ymax <- max(o) | |
plot(e,o,pch=19,cex=1, xlab=expression(Expected~~-log[10](italic(p))), ylab=expression(Observed~~-log[10](italic(p))), xlim=c(0,max(e)), ylim=c(0,ymax), ...) | |
abline(0,1,col="red") | |
} | |
# automatically set ymax | |
qq(runif(1000)) | |
# if you specify a ymax that's below what it should have been, it will still automatically scale | |
qq(runif(1000), ymax=1) | |
# if you specify ymax above max observed -logp, the y axis will expand | |
qq(runif(1000), ymax=10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment