0

我有一个带有观察结果的数据集,我需要在网格上插入它。我使用了 gstat 包中的 idw 函数。它进行插值,但将一些值保留为 NA。我还尝试了 akima 的 interp 函数,专门用于 extrap=TRUE,但它创建了不切实际的值。有谁知道,我怎样才能实现这些缺失的值?代码如下:

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))

我得到这样一张地图: 只是一大片缺失的数据

预先感谢您的帮助!

4

0 回答 0