[R] contour lines with number labels in lattice?

Martin Ivanov tramni at abv.bg
Wed Jul 18 14:37:46 CEST 2012


 Dear R users,

I am new to lattice but am trying to get to grips with it. 
I need to add contour lines for the topography to a plot I created with spplot. The topography is available as a
SpatialPixelsDataFrame object Z_sfc. If I plot it as spatial lines, after converting to a SpatialLines object:
imageZ <- as.image.SpatialGridDataFrame(x=Z_sfc);
cLZ <- contourLines(x=imageZ$x, y=imageZ$y, z=imageZ$z, levels = pretty(range(imageZ$z, na.rm=TRUE), 5));
sldfZ_sfc <- ContourLines2SLDF(cL=cLZ, proj4string=CRS(proj4string(Z_sfc)))
topography <- list("sp.lines", sldfZ_sfc, first=FALSE, col="black");

and then using the sp.layout=topgraphy argument to spplot, I lose the number labels on the lines. 
Is it possible in lattice to print the height of the isolines just as it is printed with contour?

I tried with contour, it does work with SpatialPixelsDataFrame, but unfortunately contour does not seem work with lattice. And the lattice equivalent contourplot does not recognise SpatialPixelsDataFrame objects. Is it possible somehow to add a contour plot of Z_sfc to my plot?


Many thanks in advance.

Martin



More information about the R-help mailing list