0

how can I tell the spplot function in R to sort the rasters in a different order? Here I have an example with 12 rasters, but I want them in 2 rows and 6 columns instead of 3 rows and 4 columns. I found the grid.arrange function but it doesn't help me because it would plot all rasters including the colour scale. Here is some code to create an example:

library(sp)
library(raster)
r1 <- raster(nrows = 10, ncols = 10, res = 0.5, xmn = -1.5, xmx = 1.5, ymn = -1.5, ymx = 1.5, vals = 0.3)
rr <- lapply(1:12, function(i) setValues(r1,runif(ncell(r1))))
rstack <- stack(rr)
spplot(rstack)

enter image description here

benschbob91
  • 155
  • 12
  • Provide some example dataset so that we can try to solve your problem. Please visit how to make reproducible example in r https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. – UseR10085 Oct 07 '19 at 04:03

2 Answers2

1

spplot(rstack, layout = c(2,6)) will give you the desired output.

UseR10085
  • 7,120
  • 3
  • 24
  • 54
0

I have tried spplot(rstack, layout = c(6,2)) rather spplot(rstack, layout = c(6,2)). It works for me.

Tao Li
  • 21
  • 5
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 16 '23 at 08:59