具有 NaN 值的数据集,用于使用 R 填充的等高线图

Dataset with NaN values for a filled contour plot with R

我无法使用 R 正确绘制数据。我从足球场获得了测量值,但没有为每个网格填充测量值。

这是我的数据集 contour_map_R.csv 在 https://db.tt/1L7cxilB

用图像函数绘制出来的样子是这样的

任何人都可以提供创建填充等高线图的示例吗?

非常感谢!

如评论中所述,您需要有完整的数据才能计算等高线。因此,您必须以某种对您的情况有意义的方式插入或替换您的缺失值。我在下面提供了几个选项,但您需要提出使用一种方法而不是另一种方法的基本原理,以及是否需要更复杂的地统计方法。此外,您可以插入比当前更精细的网格,以产生更平滑的结果(以可能构成数据为代价)。

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)

如果这就是您要查找的内容,您可以通过对插值栅格(tpip)使用 filledContour() 函数来获得填充轮廓。