# Interpolate temperature data (shapefile) using R

The answer below solved my fist question, so I edit my question as follows:

I have a shapefile given with the attributes lat, lon, elevation and temperature.

So far I have a script that interpolates only the temperature data:

``````#read shapefile:
#grid shapefile:
shape.grid <- spsample(shape, type = "regular", offset = (c1,1))
gridded(shape.grid) <- TRUE

#kriging:
test <- krige(Temperatur~1, shape, shape.grid)
spplot(test[[1]])
``````

Now my problem is that I should also need to consider the elevation, since the temperature is often dependant on this parameter. How can I do this?

• With `r` questions it's useful to provide a minimal reproducible example so we can test solutions. Can you edit your question either to include a link to your shapefile, either in its original location or use a file sharing site?
– Phil
Commented Mar 4, 2016 at 16:47
• I'm really curious... Are you attempting this in the R-ArcGIS Bridge, or running in straight R? Commented Mar 4, 2016 at 21:39
• I will upload a shape file tomorrow. I have a R-Arcgis bridge running but first I want to do a stand-alone script and then maybe later edit it to implement the script into arcgis :) Commented Mar 5, 2016 at 15:20
• I uploaded my .gdb with the shapefile to my google drive: drive.google.com/… Any help would be greatly appreciated :) Commented Mar 6, 2016 at 18:59
• @Phil did you get the chance to try a solution to interpolate the data considering the elevation? :) Commented Mar 10, 2016 at 7:47

You didn't pass `shape.grid` to `krige`. Try:
``````library(gstat)
Your example does not work as is, `ssample` should have been `spsample`. For your second question, you will need a grid with elevation data.
• use `spplot` instead of `plot`; I edited my answer. Commented Mar 7, 2016 at 9:10