https://github.com/NathanWeinstein/Angiogenesis-Model
Raw File
Tip revision: 0f67e1a0ffdaaf4991b588b1e970566c4b01b1f4 authored by NathanWeinstein on 08 November 2017, 17:38:49 UTC
Update ECexplorer.R
Tip revision: 0f67e1a
matrixPlotter.R
# ----- Define a function for plotting a matrix ----- #
MatrixPlot <- function(x, marlist = c(2,2,2,2), aboveaxis = FALSE ,...){
	min <- min(x)
	max <- max(x)
	yLabels <- rownames(x)
	xLabels <- colnames(x)
	title <-c()
	# check for additional function arguments
	if( length(list(...)) ){
		Lst <- list(...)
		if( !is.null(Lst$zlim) ){
			min <- Lst$zlim[1]
			max <- Lst$zlim[2]
		}
		if( !is.null(Lst$yLabels) ){
			yLabels <- c(Lst$yLabels)
    		}
		if( !is.null(Lst$xLabels) ){
			xLabels <- c(Lst$xLabels)
		}
		if( !is.null(Lst$title) ){
			title <- Lst$title
		}
	}
	# check for null values
	if( is.null(xLabels) ){
		xLabels <- c(1:ncol(x))
	}
	if( is.null(yLabels) ){
   		yLabels <- c(1:nrow(x))
	}
	#layout(matrix(data=c(1,2), nrow=1, ncol=2), widths=c(4,1), heights=c(1,1)) To show the colormap
	# Red and green range from 0 to 1 while Blue ranges from 1 to 0
	ColorRamp <- 	rgb( seq(0,1,length=256),  # Red
                   	seq(0,1,length=256),  # Green
                   	seq(0.3,0,length=256))  # Blue
	ColorLevels <- 	seq(min, max, length=length(ColorRamp))
 	# Reverse Y axis
 	reverse <- nrow(x) : 1
 	yLabels <- yLabels[reverse]
 	x <- x[reverse,]
	# Data Map
	par(mar = marlist)
	image(1:length(xLabels), 1:length(yLabels), t(x), col=ColorRamp, xlab="",
	ylab="", axes=FALSE, zlim=c(min,max))
	if( !is.null(title) ){
		title(main=title)
	}
	if(aboveaxis){
		axis(ABOVE<-3, at=1:length(xLabels), labels=xLabels, cex.axis=0.7)
	}
	axis(BELOW<-1, at=1:length(xLabels), labels=xLabels, cex.axis=0.7)
	axis(LEFT <-2, at=1:length(yLabels), labels=yLabels, las= HORIZONTAL<-1,
	cex.axis=0.7)
	grid(nx = ncol(x), ny = nrow(x), lty = "solid", lwd = 2, col = rgb(0,0,1))

 	# Color Scale
 	#par(mar = c(3,2.5,2.5,2))
 	#image(1, ColorLevels,
 	#     matrix(data=ColorLevels, ncol=length(ColorLevels),nrow=1),
 	#     col=ColorRamp,
 	#     xlab="",ylab="",
 	#     xaxt="n")
	#layout(1)
}
# ----- END plot function ----- #
back to top