How to easily visualize a matrix?

Viewed 16741

When doing matrix operations, I would like to be able to see what the results of my calculations are, at least to get a rough idea of the nature of the matrices going in and coming out of the operation.

How can I plot a matrix of real numbers, so that the x axis represents columns, the y represents rows, and the color or size of a point represents the cell value?

Ultimately, I would like to display multiple plots, e.g. the right and left hand sides of an equation.

Here is some example code:

a <- matrix(rnorm(100), ncol = 10)
b <- diag(1,10)
c <- a*b

par(mfrow = c(1,3))
plot.matrix.fn <- function(m) {
   #enter answer to this question here
}
lapply(list(a,b,c), plot.matrix.fn)

update: since posting this question, I found that there are some great examples here: What techniques exists in R to visualize a "distance matrix"?

3 Answers
Related