R write function that calls plot() first time and points() on subsequent calls -
R write function that calls plot() first time and points() on subsequent calls -
i wondering if possible encapsulate behavior in single function. have next code qq-plot of p-values adapted http://gettinggeneticsdone.blogspot.ca/2010/07/qq-plots-of-p-values-in-r-using-base.html
i trying first time plot figure series labels , reddish line on y=x axis, , on subsequent calls add together additional points different info frames using color specified. however, none of behavior expected. if don't explicitly set par(new=true) sec phone call ggd.qqplot() overwrite first. if explicitly phone call 2 plots super-imposed on each other (not points axes, etc). right check should doing in if statement... if possible.
ggd.qqplot = function(pvector, color="black", main=null, ...) { o = -log10(sort(pvector,decreasing=f)) e = -log10( 1:length(o)/length(o) ) if(par()$new) { points(e,o,cex=1, col=color) } else { par(new=true); plot(e,o,pch=19,cex=1, col=color, main=main, ..., xlab=expression(expected~~-log[10](italic(p))), ylab=expression(observed~~-log[10](italic(p))), xlim=c(0,max(e)), ylim=c(0,max(o))) lines(e,e,col="red") } } pvals <- as.matrix(runif(10000), 1000, 10); ggd.qqplot(pvals[,9]+1e-20); ggd.qqplot(pvals[,8]+1e-20, "green");
r plot points
Comments
Post a Comment