I have a matrix like so:

xy <- matrix(rnorm(128 * 64),128,64)

and I want to turn it to a raster in WGS84.

I also have a longitude and a latitude matrix:

with the following dimensions:

min(lon) <- 0
max(lon  <- 357.1875
min(lat) <- -87.8638
max(lat) <- 87.8638

the latitude and longitude came for a netCDF, and for some reason the longitude is from 0 - 360 instead of -180 to 180, for now I am not worried about that though.

I try to create the raster like so:

r <- raster(xy, xmn = min(lon), xmx = max(lon), ymn = min(lat), ymx = max(lat), crs = CRS("+init=epsg:4326"))

but this returns:

enter image description here

1 Answer 1


Check out raster::rotate for your coordinate issues.

If that doesn't solve the orientation I sometimes need to use raster::flip. Occasionally I get text file grids that require this treatment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.