Skip to content
Prev 4835 / 29559 Next

contour lines on a plot

Dear users,

First of all, I'd like to wish you a happy new year, with many nice 
results from R.
I have a graphical problem when plotting kriging results. I first want 
to see results on a plot and, secondary, I'd like to add contour lines 
to the plot. The problem is that lines are at a wrong place with respect 
to the x-axis.
Does anyone know what could generate this?

Many thanks,

max

here's my script

library(sp)
library(gstat)
# read data file
d<-read.table("file.txt")
coordinates(d)<-~long+lat
#create ? grid to perform kriging
x.range=c(-4.5,30)
y.range=c(40,55)
grd<-expand.grid(x=seq(from=x.range[1], to=x.range[2], by=1/6), 
y=seq(from=y.range[1], to=y.range[2], by=1/6))
coordinates(grd)=~x+y
gridded(grd)=TRUE
#ordinary kriging
g<-gstat(id="K1", formula=K1~1, data=d)
p<-predict(g, model=v.fit, newdata=range)
pts<-list("sp.points", d,pch=20, col="black", cex=1)
spplot(p,zcol="K1.pred",col.regions=gray(0:100/100), cuts=40, 
sp.layout=list(pts), pretty=T)
contour(p, add=T, nlevels=2)