[R-sig-Geo] contour lines on a plot

Maxime Pauwels Maxime.Pauwels at univ-lille1.fr
Mon Jan 19 18:02:40 CET 2009


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)

-- 
Maxime Pauwels
Researcher ID: http://www.researcherid.com/rid/A-1745-2009

Laboratoire de Génétique et Evolution des Populations Végétales
http://www.univ-lille1.fr/gepv
Tel  : +33 3 20 43 40 76
Fax  : +33 3 20 43 69 79
			
«Impose ta chance, serre ton bonheur et va vers ton risque. A te regarder, ils s’habitueront.»
René Char




More information about the R-sig-Geo mailing list