#!/usr/bin/Rscript scaleValues<-1 title<-"" args <- commandArgs(trailingOnly = TRUE) if(length(args)>1){ inputFile<-args[1] outFile<-args[2] } else { cat("Usage: ./correlationPlot.R \n"); cat(" <InputData>: Tab separated file of values with column names REQUIRED\n"); cat(" <OutputFile.eps>: Output eps file REQUIRED\n"); cat(" <SCALING>: Scale correlation values (default 1) set 0 to deactivate OPTIONAL\n"); cat(" <TITLE>: Title of the plot OPTIONAL\n"); q() } if(length(args)>2){ scaleValues<-args[3] } if(length(args)>3){ title<-args[4] } panel.hist <- function(x, ...) { usr <- par("usr"); on.exit(par(usr)) par(usr = c(usr[1:2], 0, 1.5) ) h <- hist(x, plot = FALSE) breaks <- h$breaks; nB <- length(breaks) y <- h$counts; y <- y/max(y) rect(breaks[-nB], 0, breaks[-1], y, col="cyan", ...) } if(scaleValues!=0){ panel.cor <- function(x, y, digits=2, prefix="", cex.cor, ...) { usr <- par("usr"); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r <- cor(x, y) txt <- formatC(c(r, 0.0123456789), digits=digits, format="f")[1] txt <- paste(prefix, txt, sep="") absr<- abs(cor(x, y)) abstxt<- formatC(c(absr, 0.0123456789), digits=digits, format="f")[1] abstxt <- paste(prefix, abstxt, sep="") if(missing(cex.cor)) cex.cor <- 0.8/strwidth(abstxt) text(0.5, 0.5, txt, cex = cex.cor * absr) } } else { panel.cor <- function(x, y, digits=2, prefix="", cex.cor, ...) { usr <- par("usr"); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r <- cor(x, y) txt <- formatC(c(r, 0.0123456789), digits=digits, format="f")[1] txt <- paste(prefix, txt, sep="") absr<- abs(cor(x, y)) abstxt<- formatC(c(absr, 0.0123456789), digits=digits, format="f")[1] abstxt <- paste(prefix, abstxt, sep="") if(missing(cex.cor)) cex.cor <- 0.8/strwidth(abstxt) text(0.5, 0.5, txt, cex = cex.cor * 0.8 ) } } data<-read.table(inputFile, sep="\t",header=T) setEPS() postscript(outFile) #pairs(data, lower.panel=panel.smooth, upper.panel=panel.cor,pch='.', main=title) names(data) <- c("Unif MS1", "Unif MS2", "Entropy", "MFE CO", "Rfam CO", "Native Cont") pairs(data, lower.panel=panel.smooth, upper.panel=panel.cor,diag.panel=panel.hist,pch='.', main=title) dev.off()