Does the image matrix R () rotate?

I read the docs for R image() , but I don't get it. Why is this matrix:

 > mat1 [,1] [,2] [,3] [1,] 1 0 1 [2,] 0 1 0 [3,] 0 0 0 

Set up like this:

 > image(c(1:3), c(1:3), mat1) 

do the following:

enter image description here

And how can I make the layout the same as the printed matrix? It is not a matter of simply transposing the transpose to flip x and y, since it ends with the upside down image.

+7
r image
source share
1 answer

You can change the matrix and then transpose.

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

This is confusing because it draws a row from bottom to top, but R indexes the matrices in a column, from top to bottom. Thus, the pixels in the first row from left to right correspond to the first column in the matrix, from top to bottom.

+9
source share

All Articles