Path: blob/master/sandbox/symposium2013/R/page.Distributions.R
1433 views
1# Histogram, QQPlot and ECDF plots aligned by scale for comparison2page.Distributions <- function (R, colorset = c("black", "#00008F", "#005AFF", "#23FFDC", "#ECFF13", "#FF4A00", "#800000"), ...) {3require(PerformanceAnalytics)4op <- par(no.readonly = TRUE)5# c(bottom, left, top, right)6par(oma = c(5,0,2,1), mar=c(0,0,0,3))7layout(matrix(1:(4*NCOL(R)), ncol=4, byrow=TRUE), widths=rep(c(.6,1,1,1),NCOL(R)))8# layout.show(n=21)9chart.mins=min(R, na.rm=TRUE)10chart.maxs=max(R, na.rm=TRUE)11means=colMeans(R, na.rm=TRUE)12row.names = sapply(colnames(R), function(x) paste(strwrap(x,10), collapse = "\n"), USE.NAMES=FALSE)13for(i in 1:NCOL(R)){14if(i==NCOL(R)){15plot.new()16text(x=1, y=0.5, adj=c(1,0.5), labels=row.names[i], cex=1.1)17chart.Histogram(R[,i], main="", xlim=c(chart.mins, chart.maxs),18breaks=seq(round(chart.mins, digits=3)-0.005, round(chart.maxs, digits=3)+0.005, by=0.005), note.lines=boxplot.stats(as.vector(R[,i]))$stats, note.color=colorset[2],19show.outliers=TRUE, methods=c("add.normal"), colorset = colorset)20abline(v=0, col="darkgray", lty=2)21chart.QQPlot(R[,i], main="", pch=20, envelope=0.95, col=colorset, ylim=c(chart.mins, chart.maxs), cex=0.5)22abline(v=0, col="darkgray", lty=2)23chart.ECDF(R[,i], main="", xlim=c(chart.mins, chart.maxs), lwd=2, colorset=colorset)24abline(v=0, col="darkgray", lty=2)25}26else{27plot.new()28text(x=1, y=0.5, adj=c(1,0.5), labels=row.names[i], cex=1.1)29chart.Histogram(R[,i], main="", xlim=c(chart.mins, chart.maxs),30breaks=seq(round(chart.mins, digits=3)-0.005, round(chart.maxs, digits=3)+0.005, by=0.005), note.lines=boxplot.stats(as.vector(R[,i]))$stats, note.color=colorset[2],31xaxis=FALSE, yaxis=FALSE, show.outliers=TRUE, methods=c("add.normal"), colorset = colorset32)33abline(v=0, col="darkgray", lty=2)34chart.QQPlot(R[,i], main="", xaxis=FALSE, yaxis=FALSE, pch=20, envelope=0.95, col=c(colorset), ylim=c(chart.mins, chart.maxs), cex=0.5)35abline(v=0, col="darkgray", lty=2)36chart.ECDF(R[,i], main="", xlim=c(chart.mins, chart.maxs), xaxis=FALSE, yaxis=FALSE, lwd=2, colorset=colorset)37abline(v=0, col="darkgray", lty=2)38}39}40par(op)41}42434445