It is very difficult to help if you do not provide example data (as data, not by printing the data). But your approach does not look right to me. Why do you use rasterize
? Here is a simplified workflow:
library(raster)
library(fields)
utm.prj = " +proj=utm +zone=21 +south +datum=WGS84 +units=m +no_defs "
xy <- divetemps[, c("lon.x", "lat.y")]
rast <- raster(ext=extent(xy)+1000, crs=utm.prj, resolution = 500)
krgm <- fields::Krig(xy, divetemps$depthbin1)
surface <- raster::interpolate(rast, krgm)
plot(surface)
I think this is conceptually better, but you may still not like the output, and perhaps should. I would expect that you would prefer the output of at Thin Plate Spline model:
m <- fields::Tps(xy, divetemps$depthbin1)
surface <- raster::interpolate(rast, m)
And you may consider to not use another interpolation method,only x
and y
but how can we know without data?also an additional variable such as elevation to predict temperature. See ?interpolate