[R] the proper way to use panel functions in lattice package?

Deepayan Sarkar deepayan.sarkar at gmail.com
Mon Feb 13 22:37:07 CET 2006


On 2/10/06, simon chou <sentientc at gmail.com> wrote:
> Hi,
> I was trying to stack a topographic map readed in from esri shapefile with a
> contour map and a vector map. However, the plotMap(maptools) and
> contourplot(lattice) do not seem to work well on top of each other. Here is
> part of my code.
>
>
>       xrange<-range(225000:350000)
>
>       yrange<-range(2685000:2810000)
>
>       basemap <- read.shape("Twn25_town_dxf_Polygon.shp")
>
>       plot.Map(basemap,xlim=xrange,ylim=yrange,fg=0,ol=8,xlab="",ylab="")
>
>
>
>       contourplot(var1.pred~x+y, spcgrid, aspect = "xy",label.style="align")
>
>
>
> I have tried to put panel function under plot.Map() but it gave some error
> message about  some argoument matches other arguments.
>
>
>
>       >plot.Map
> (basemap,xlim=xrange,ylim=yrange,fg=0,ol=8,xlab="",ylab="",panel=function(x,y){
>
>       +contourplot(var1.pred~x+y, spcgrid, aspect = "xy",label.style=
> "align")})
>
>       Error in plot.default(xylims$x,xylims$y, asp=1,type="n",...):
>
>         argument 9 matches multiple formal arguments
>
>
>
> I also tried to put plotMap() into contourplot()'s panel but plotMap cover
> up the conour. Maybe, there is something I miss in here.

Yes, namely that `standard graphics' (the 'graphics' package)
functions (like plotMap) don't (easily) work with grid graphics (the
'grid' package) which lattice uses. Unfortunately, I have no idea if
there are any grid compatible equivalents of plotMap.

> What went wrong there? Also, is there any diffeence between
> contourplot(lattice) and counterLine(base)? These 2 functions seem to give
> difference contour from the same data set. contourplot(lattice) seem to give
> better looking contour than contourLine() or contour().

contourplot uses contourLines (which I assume is what you meant)
internally, so any differences probably stem from the choice of
default arguments.

>
> ps. I krige 1700+ simulated observations into 4000+ regular spaced data to
> get contour.

Deepayan




More information about the R-help mailing list