4

I'm plotting a shapefile in R and would like to delete certain borders to "group" shapes together. For example, in the plot below, how would I delete the borders between the three blue counties and between the red counties?

library(maptools)

xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
 IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))

COLS <- rep(2,100)

COLS[c(9,31,82)] <- 4

plot(xx, axes=TRUE, las=1, col=COLS)

plot

0

1 Answer 1

4

E.g. with gUnaryUnion from the rgeos package:

library("rgeos")
plot(gUnaryUnion(xx), col = "red", axes = TRUE)
plot(gUnaryUnion(xx[c(9, 31, 82), ]), col = "blue", add = TRUE)

plot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.