如 cmets 中所述,您需要拥有完整的数据才能计算轮廓。因此,您必须以某种对您的情况有意义的方式插入或替换您的缺失值。我在下面提供了几个选项,但您需要提出使用一种方法而不是另一种方法的理由,以及是否需要更复杂的地统计方法。此外,您还可以插入比当前更精细的网格,以产生更平滑的结果(以可能构成数据为代价)。
d <- read.csv("contour_map_R.csv")
library(raster)
r <- raster(as.matrix(d))
contour(r)
v <- getValues(r)
xy <- xyFromCell(r, 1:ncell(r))
## Interpolate using a thin-plate spline:
library(fields)
tps <- Tps(xy, v)
tp <- interpolate(r, tps)
plot(tp)
contour(tp, add=T)
## Alternatively, interpolate using nearest idw():
library(gstat)
dxy <- data.frame(x=xy[,1], y=xy[,2], v)
dxy <- dxy[complete.cases(dxy),]
id <- gstat(formula = v~1, locations = ~x+y, data=dxy)
ip <- interpolate(r, id)
plot(ip)
contour(ip, nlevels=5, add=T)
如果这就是您要查找的内容,您可以通过在插值栅格(tp 或 ip)上使用 filledContour() 函数来获得填充轮廓。