I have a dataset with observations and I need to interpolate it over the grid. I used idw function from gstat package. It makes interpolation but leaves some values as NA. I also tried interp funtion from akima, specializing extrap=TRUE, but it created unrealistic values. Have anybody an idea, how I could fulfill these missing values? Code is below:
winter1 <- winter
winter1$x <- winter1$Lon
winter1$y <- winter1$Lat
coordinates(winter1) = ~x + y
dx <- as.numeric(c(9,30.5))
dy <- as.numeric(c(53.8,66))
grd <- expand.grid(x = seq(from = dx[1], to = dx[2], by = 0.1), y = seq(from = dy[1], to = dy[2], by = 0.1))
coordinates(grd) <- ~x + y
winter_idw <- idw(formula = winter$Secchi ~ 1, locations = winter1, newdata = grd)
winter_idw <- as.data.frame(winter_idw)
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
rng = range(c(0,10))
p <- ggplot(data = world)+
geom_raster(data = v, mapping=aes(x = x, y = y, fill=var1.pred))+
scale_fill_gradient2(low = "blue",
mid = "yellow",
high = "red",
breaks=seq(0,10,2),
midpoint=5,
limits=c(floor(rng[1]), ceiling(rng[2])))+
borders("world", colour="black",xlim = c(9,30.5), ylim = c(53.8,66))+
geom_sf(fill="antiquewhite") +
coord_sf(xlim=c(9,30.5), ylim=c(53.8,66))+
theme(plot.title = element_text(hjust = 0.5))
Thank you in advance for your help!