1

first time user here. I am converting matrix into im object from package spatstat. However, top left value from the matrix mat[1,1] is written in the down left corner of the image e.g. the im function reads the rows of the matrix from top to bottom but writes them into im starting from bottom. Tried to specify yrow argument of im() to be seq() in reverse order but still same result.Suggestions how to fix this?

    require(spatstat)

    mat <- matrix(seq(1,20, by=1), nrow=4, ncol=5)
    print(mat)
    im <- im(mat, xcol = seq(1,5), yrow = seq(4,1))
    plot(im, axes = T)
Djaner Emin
  • 35
  • 1
  • 6

1 Answers1

1

There are two ways around this. In the latest development version of spatstat from github you can transform between different layouts. See help(transmat) for details. The layout you are providing is called 'European' and the layout used for spatstat is called 'spatstat', so you can do:

require(spatstat)
mat <- matrix(seq(1,20, by=1), nrow=4, ncol=5)
m <- transmat(mat, from = 'European', to = 'spatstat')
i <- im(m)
plot(i, axes = TRUE)

If you don't have the development version of spatstat you can simply do:

require(spatstat)
mat <- matrix(seq(1,20, by=1), nrow=4, ncol=5)
m <- mat[4:1,]
i <- im(m)
plot(i, axes = TRUE)
Ege Rubak
  • 4,347
  • 1
  • 10
  • 18