[R-sig-Geo] plot shape file using lattice xyplot

Roger Bivand Roger.Bivand at nhh.no
Thu Dec 17 08:20:35 CET 2009


On Wed, 16 Dec 2009, Zia Ahmed wrote:

> Hi,
>
> I am trying to plot a shape file  in R. I can do  it easily using plot or 
> spplot function.  But I want plot this map with  lattice xyplot function. Any 
> one has any idea? I do not want use "maps" package.
>
> Help will be appreciated...
>
> Thanks
>
> Zia
>
> library(maptools)
> library(lattice)
> bound<-read.shape("Boundary.shp")

This is no longer possible in current maptools - read.shape() is no longer 
in the package namespace.

> #OR
> bound<-readShapePoly("Boundary.shp")
> plot(bound)
> spplot(bound)
>
> # Or following way
>
> bound<-Map2poly(bound)
> xybd<-attr(bound,"maplim")
>

Nor is this possible now - after years of deprecation, these S3 classes 
are now defunct and their methods not in the namespace of maptools. Only 
S4 sp classes are available. Retaining the antiquated older versions, and 
trying to help users who instist on not reading warnings about 
deprecation, has ceased to be worthwhile.

Everyone looking for advise in the archives will see messages mentioning 
read.shape() etc., this statement should suffice to indicate what is 
going on.

Roger

> plot(xybd$x,xybd$y, type="n",asp=1, xlab="", ylab="")
> for (i in 1:length(bound)) lines(bound[[i]]) # How do I apply this code in 
> following  panel.function of  xyplot?
>
>
> windows(width=5, height=5)
> xyplot(y~x, as.data.frame(tala),pch=1, cex=.8,col="black",
>      xlab=list("Easting (m)",cex=.9),ylab=list("Northing (m)",cex=.9),
>      aspect = "iso",
>      panel = function(...) {
>             panel.xyplot(...)
>             panel.abline(h = 0:4*5000 + 545000, v= 0:4*5000 + 2650000,
>             col = "light grey")
>             panel.points(coordinates(tala.nr),cex=.95,pch=20, col="black")
>             panel.text(2671000, 563000, cex=1, " (a)")
>             },
> )
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list