I have a very large data set that includes long/lat and average precipitation (appt). I'm trying to interpolate some additional data points in order to create a ggplot
of the average precipitation over select states. However, I'm not sure how exactly to interpolate the data. The results of the interp
function is producing NA
s.
How would I interpolate additional data points(~5,000 appt) given longitude/latitude?
Why am I getting NA
s when using the interp
function ?
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")
Current Code :
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))
Current Output : 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