Question

I want to create an interpolation grid consisting of spatial data points to later use for kriging in R. I have been working in the sp and gstat packages. The code I am working with works, but my grid does not include all of the points and I want to expand it, but I can't seem to get it right.

The code I am working with is here (my data.frame is kr.data):

x.range <- as.integer(range(kr.data@coords[,1]))
y.range <- as.integer(range(kr.data@coords[,2]))
data.grd <- expand.grid(x=seq(from=x.range[1], to=x.range[2], by=0.5),  
y=seq(from=y.range[1], to=y.range[2], by=0.5))

coordinates(data.grd) <- ~x+y
gridded(data.grd) <- TRUE
plot(data.grd, cex=0.5)
points(kr.data, pch=1, col='red', cex=0.7)

I wanted to add the output to show the points concentrated in the lower right corner, off the grid, but I am new and not sure how to add this. Can anyone offer a suggestion on where to find help making a grid with spatial data or where to change my code? When I alter my code to expand the grid, my data points are no longer visible. I am new at working with spatial data in R.

Was it helpful?

Solution

Your truncation resulting from as.integer integer is probably cutting off the values at the high end of the ranges. Try instead:

x.range <- as.integer(range(kr.data@coords[,1])) + c(0,1)
y.range <- as.integer(range(kr.data@coords[,2])) + c(0,1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top