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

Zia Ahmed zua3 at cornell.edu
Thu Dec 17 02:27:46 CET 2009


Thanks Andrews. It works fine. Nothing wrong with sp plot.  I need to 
plot boundary around of sampling locations. R-script I have  written, I 
used xyplot and levelplot.

Thanks  again

Zia

Felix Andrews wrote:
> What's wrong with using spplot? It is based on xyplot anyway.
>
> If you want to use xyplot, you can use the panel function that sp defines:
> sp.polygon
>
> You can read in the shapefile with the RGDAL package:
> shp <- readOGR(...)
>
>
> 2009/12/17 Zia Ahmed <zua3 at cornell.edu>:
>   
>> 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")
>> #OR
>> bound<-readShapePoly("Boundary.shp")
>> plot(bound)
>> spplot(bound)
>>
>> # Or following way
>>
>> bound<-Map2poly(bound)
>> xybd<-attr(bound,"maplim")
>>
>> 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
>>
>>     
>
>
>
>



More information about the R-sig-Geo mailing list