'Why does raster plot "north" as "south"?
I have no problems using the raster package when I stay within the confines of the provided functions but when I go off-piste and manually mess with the internals I get into trouble. In this example I am trying to change raster matrix element but is seems that "south" gets turned into "north" when when plotting? What is happening? Thanks.
# test raster plotting
library(raster)
#> Loading required package: sp
m1 <- matrix(1,nrow=10,ncol=10)
r1 <- raster::raster(m1)
r1 <- setExtent(r1,c(1,10,1,10))
r1
#> class : RasterLayer
#> dimensions : 10, 10, 100 (nrow, ncol, ncell)
#> resolution : 0.9, 0.9 (x, y)
#> extent : 1, 10, 1, 10 (xmin, xmax, ymin, ymax)
#> crs : NA
#> source : memory
#> names : layer
#> values : 1, 1 (min, max)
# looks as we expect, all 1
plot(r1)
# set first, bottom, most southerly row, to zero
m1[1,] = 0
r2 <- raster::raster(m1)
r2 <- setExtent(r2,extent(r1))
r2
#> class : RasterLayer
#> dimensions : 10, 10, 100 (nrow, ncol, ncell)
#> resolution : 0.9, 0.9 (x, y)
#> extent : 1, 10, 1, 10 (xmin, xmax, ymin, ymax)
#> crs : NA
#> source : memory
#> names : layer
#> values : 0, 1 (min, max)
plot(r2)
# top, most northerly row is displayed as zero
Created on 2022-02-19 by the reprex package (v2.0.1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|