I was given a csv file which has lon, lat, z value and I converted that to a raster
library(terra)
library(rnaturalearth)
world_shp <- rnaturalearth::ne_countries(return) |> vect()
my_proj <- crs(world_shp)
temp_rast <- terra::rast(temp[, c("lon", "lat", "z")], crs = my_proj)
temp_rast
class : SpatRaster
dimensions : 720, 1440, 1 (nrow, ncol, nlyr)
resolution : 0.25, 0.25 (x, y)
extent : 0, 360, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : proj=longlat ellps=WGS84 towgs84=0,0,0,0,0,0,0 no_defs
source : memory
name : z
min value : -77.92158
max value : 27.33242
When I overlay shapefile on raster North and South America do not show up on the raster. Why is this happening?
terra::plot(temp_rast)
terra::plot(world_shp, add = T)
CodePudding user response:
Your data have global longitude from 0 to 360 instead of the (more) conventional -180 to 180. To fix that you can do
r <- rotate(temp_rast)