R image() plots matrix rotated?

You could reverse the matrix, then transpose.

mat1 <- apply(mat1, 2, rev)
image(1:3, 1:3, t(mat1))

It's confusing because it draws by row from bottom up, but R indexes matrices by column, top down. So, the pixels in the first row, from left to right, correspond to the first column in the matrix, top down.


when viewing a matrix as image using something like this:

m <- some matrix

image(m) R turns it upside down. After some small headaches, I found this quick fix.

image(m[,nrow(m):1])

nrow(m) gives the number of rows of your matrix

nrow(m):1 makes a sequence backwards

Tags:

Image

R