R image() plots matrix rotated?

前端 未结 2 2013
孤街浪徒
孤街浪徒 2021-02-07 10:06

I\'ve been reading the docs for R image() but I don\'t get it. Why does this matrix:

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


        
2条回答
  •  情书的邮戳
    2021-02-07 10:47

    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.

提交回复
热议问题