shp <- try(library(shapefiles))
if (class(shp) != "try-error") {
try1 <- read.shapefile(paste(system.file("etc/columbus",
package="spdep")[1], "columbus", sep="/"))
shppolys <- shape2poly(try1, as.character(try1$dbf$dbf$NEIGNO))
shpbbs <- shape2bbs(try1)
plotpolys(shppolys, shpbbs)
title(main="Polygons for Columbus OH from shapefiles package")
}
map <- try(library(maptools))
if (class(map) != "try-error") {
try2 <- read.shape(system.file("etc/columbus/columbus.shp",
package="spdep")[1])
mappolys <- Map2poly(try2, as.character(try2$att.data$NEIGNO))
mapbbs <- Map2bbs(try2)
plotpolys(mappolys, mapbbs)
title(main="Polygons for Columbus OH from maptools package")
if (class(shp) != "try-error") {
plotpolys(shppolys, shpbbs)
plotpolys(mappolys, mapbbs, add=TRUE, border="red", lty="dotted")
title(main="Polygons for Columbus OH overplotted from both packages")
}
}
Run the code above in your browser using DataLab