[Returnanalytics-commits] r2307 - pkg/PApages/sandbox
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jan 17 00:34:43 CET 2013
Author: peter_carl
Date: 2013-01-17 00:34:43 +0100 (Thu, 17 Jan 2013)
New Revision: 2307
Added:
pkg/PApages/sandbox/page.Distributions.R
Log:
- function that plots histogram, qqplot, and ecdf aligned for comparison
Added: pkg/PApages/sandbox/page.Distributions.R
===================================================================
--- pkg/PApages/sandbox/page.Distributions.R (rev 0)
+++ pkg/PApages/sandbox/page.Distributions.R 2013-01-16 23:34:43 UTC (rev 2307)
@@ -0,0 +1,43 @@
+
+# Histogram, QQPlot and ECDF plots aligned by scale for comparison
+page.Distributions <- function (R) {
+ require(PerformanceAnalytics)
+ op <- par(no.readonly = TRUE)
+ # c(bottom, left, top, right)
+ par(oma = c(5,0,2,1), mar=c(0,0,0,3))
+ layout(matrix(1:(4*NCOL(R)), ncol=4, byrow=TRUE), widths=rep(c(.6,1,1,1),NCOL(R)))
+ # layout.show(n=21)
+ chart.mins=min(R, na.rm=TRUE)
+ chart.maxs=max(R, na.rm=TRUE)
+ row.names = sapply(colnames(R), function(x) paste(strwrap(x,10), collapse = "\n"), USE.NAMES=FALSE)
+ for(i in 1:NCOL(R)){
+ if(i==NCOL(R)){
+ plot.new()
+ text(x=1, y=0.5, adj=c(1,0.5), labels=row.names[i], cex=1.1)
+ chart.Histogram(R[,i], main="", xlim=c(chart.mins, chart.maxs),
+ breaks=seq(round(chart.mins, digits=2)-0.01, round(chart.maxs, digits=2)+0.01, by=0.01),
+ show.outliers=TRUE, methods=c("add.normal"), colorset =
+ c("black", "#00008F", "#005AFF", "#23FFDC", "#ECFF13", "#FF4A00", "#800000"))
+ abline(v=0, col="darkgray", lty=2)
+ chart.QQPlot(R[,i], main="", pch=20, envelope=0.95, col=c(1,"#005AFF"), ylim=c(chart.mins, chart.maxs))
+ abline(v=0, col="darkgray", lty=2)
+ chart.ECDF(R[,i], main="", xlim=c(chart.mins, chart.maxs), lwd=2)
+ abline(v=0, col="darkgray", lty=2)
+ }
+ else{
+ plot.new()
+ text(x=1, y=0.5, adj=c(1,0.5), labels=row.names[i], cex=1.1)
+ chart.Histogram(R[,i], main="", xlim=c(chart.mins, chart.maxs),
+ breaks=seq(round(chart.mins, digits=2)-0.01, round(chart.maxs, digits=2)+0.01, by=0.01),
+ xaxis=FALSE, yaxis=FALSE, show.outliers=TRUE, methods=c("add.normal"), colorset =
+ c("black", "#00008F", "#005AFF", "#23FFDC", "#ECFF13", "#FF4A00", "#800000"))
+ abline(v=0, col="darkgray", lty=2)
+ chart.QQPlot(R[,i], main="", xaxis=FALSE, yaxis=FALSE, pch=20, envelope=0.95, col=c(1,"#005AFF"), ylim=c(chart.mins, chart.maxs))
+ abline(v=0, col="darkgray", lty=2)
+ chart.ECDF(R[,i], main="", xlim=c(chart.mins, chart.maxs), xaxis=FALSE, yaxis=FALSE, lwd=2)
+ abline(v=0, col="darkgray", lty=2)
+ }
+ }
+ par(op)
+}
+
More information about the Returnanalytics-commits
mailing list