R image() plots matrix rotated?

前端 未结 2 2021
孤街浪徒
孤街浪徒 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条回答
  •  猫巷女王i
    2021-02-07 10:37

    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

提交回复
热议问题