插值空间数据

时间:2015-01-24 18:56:35

标签: r ggplot2 geospatial interpolation

我有一个非常大的数据集,包括长/纬度和平均降水量(appt)。我正在尝试插入一些额外的数据点,以便在选定状态下创建ggplot平均降水量。但是,我不确定如何插入数据。 interp函数的结果是生成NA s。

如果给出经度/纬度,我将如何插入额外的数据点(~5,000 appt)?

为什么我在使用NA功能时获得interp

dput:

data <- structure(list(longitude = c(-91.40953, -90.30213, -89.26907, 
  -93.32515, -94.13632), latitude = c(33.403216, 34.505369, 32.438327, 
  36.283347, 39.28965), APPT = c(90.4899996121724, 50.4899996121724, 
  30.4899996121724, 70.4899996121724, 93.4899996121724)), .Names = c("longitude", 
  "latitude", "APPT"), row.names = c(NA, 5L), class = "data.frame")

当前代码:

library(akima)

sp_data <- interp(x = data$longitude,
                  y = data$latitude,
                  z = data$APPT)

dInterp <- data.frame(expand.grid(x = sp_data$x,
                                  y = sp_data$y), z = c(sp_data$z))

当前输出:head(dInterp)

          x        y  z
1 -94.13632 32.43833 NA
2 -94.01152 32.43833 NA
3 -93.88672 32.43833 NA
4 -93.76192 32.43833 NA
5 -93.63711 32.43833 NA
6 -93.51231 32.43833 NA

1 个答案:

答案 0 :(得分:2)

问题是akima::interp没有填写每个条目。所以,当你看到唯一一个角落#34;你的数据只能看到NA。你需要向下滚动&#34;查看插值。它只填充有数据的区域:

library(akima) # should have been part of the question:

 contourplot(z ~ x+y, data=dInterp)

enter image description here

73   -90.14268 32.61400       NA
74   -90.01788 32.61400       NA
75   -89.89308 32.61400       NA
76   -89.76828 32.61400       NA
77   -89.64347 32.61400 40.94645
78   -89.51867 32.61400 37.13339
79   -89.39387 32.61400 33.32033
80   -89.26907 32.61400       NA
81   -94.13632 32.78968       NA
82   -94.01152 32.78968       NA

并且:

112  -90.26748 32.78968       NA
113  -90.14268 32.78968       NA
114  -90.01788 32.78968 51.40291
115  -89.89308 32.78968 47.58984
116  -89.76828 32.78968 43.77678
117  -89.64347 32.78968 39.96372
118  -89.51867 32.78968 36.15065
119  -89.39387 32.78968       NA
120  -89.26907 32.78968       NA
121  -94.13632 32.96535       NA

该数据框中有1600行的许多其他值集群。