I have 2 variables x and y which are Cartesian coordinates at [0,1], and z is the value of a (continuous) variable at these coordinates. The z vector has some important outliers
x<-sample(seq(0,1,0.001), replace=F)
y<-sample(seq(0,1,0.001), replace=F)
z<-runif(1001,min=0,max=1)
z[100]<-8;z[400]<-16;z[800]<-4
These outliers I would like to emphasize when presenting these data in a filled.contour
I have used until now
library(akima)
a<-interp(x,y,z)
filled.contour(a$x,a$y,a$z)
But I am not happy with this linear interpolation. For example (the outliers do not show up correctly).
I am thinking what I need is a some kind nearest neighbor “spatial” smoothing of z (based on the x,y location). Can anyone help or pinpoint to data/examples/packages/code that could help me? I would prefer a base R solution but if ggplot2 or lattice can do my job it would be fine. Any other idea/proposal of better visualization would be also welcomed.
Check out @Paul Heimstra’s answer here. They suggest thin plate spline interpolation from the fields package. If kriging is right for you, the package automap may be useful.
If you’re concerned with the interpolation of geographic values, it’s worth mentioning DG Rossiter’s online/free course on Geostatistics and Open-source statistical computing.