3

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 NAs.

How would I interpolate additional data points(~5,000 appt) given longitude/latitude?

Why am I getting NAs 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
Vedda
  • 7,066
  • 6
  • 42
  • 77
  • I'm not sure exactly what you are asking for, but I once answered another question with similar input data (Longitude, Latitude, Rain), which was `interp`olated, and then plotted with `ggplot`; see [**here**](http://stackoverflow.com/questions/19339296/plotting-contours-on-an-irregular-grid/19339663#19339663) – Henrik Jan 24 '15 at 20:24
  • @Henrik Thanks for the post. I checked it out and was able to get a contour plot. What I'm trying to do is just add additional values to my data set so that when I plot them on a map it fills in a lot of the holes....I thought `interp()` was what I needed. – Vedda Jan 24 '15 at 22:01
  • `interp` only does interpolation, so any points on the grid outside your input data will be NA. To do extrapolation, set `extrap=TRUE`. – kdauria Jan 26 '15 at 10:10

1 Answers1

2

The problem is that akima::interp does not fill in every entry. So as you look in the only one "corner" of your data, you only see NA's. You need to "scroll down" to see the interpolated values. It only fills in the region where there is data:

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

And:

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

And many other clusters of values in that dataframe with 1600 rows.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Thanks! After playing around with this in the big data file, it appears to be making points outside of the lat/long. I'm just trying to create additional points for the given lat/long so when I plot it on a map it fills in the holes. Am I using the correct function? – Vedda Jan 24 '15 at 22:14