I'm having trouble finding documentation on how to change the x and y axes from coordinates (extent) to nrow and ncol (dimension). When I plot a raster:
r1 <- raster(ncol=10, nrow=10, crs="EPSG:4326")
values(r1) <- sample(80:100, 100, replace=TRUE)
plot(r1)
The x and y axes are pulling from crs. I want x and y to be based on the number of rows and columns:
Seems like there should be an obvious solution and I'm just not finding it. I checked 
r2 <- raster(xmn=0, xmx=10, ymn=0, ymx=10, ncol=10, nrow=10, crs="EPSG:4326")
values(r2) <- sample(80:100, 100, replace=TRUE)
plot(r2) ##Desired Extent of xmn = 0, xmx=10, ymn = 0, ymx = 10
CodePudding user response:
If you just need the pixel position you could convert your raster to a matrix and plot it using image or rasterVis::levelplot
library(raster)
#> Loading required package: sp
r1 <- raster(ncol=10, nrow=10, crs="EPSG:4326")
values(r1) <- sample(80:100, 100, replace=TRUE)
m <- as.matrix(r1)
image(1:ncol(m), 1:nrow(m), m)

rasterVis::levelplot(m)

Created on 2022-01-18 by the reprex package (v2.0.0)



