I guess I needed to rephrase my awfully worded previous question (deleted it). Here's another try. I want to join to adjacent regions, in a way that their common border disappears and only their outer line can be seen.
Here's a reproducible example:
require(shapefiles)
require(sp)
xx <- readShapeSpatial(system.file("shapes/sids.shp", package="maptools")[1],
IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
# show all the subregions
plot(xx)
Now let's consider only regions regions 3 and 5
plot(xx[c(3,5),])
How can I just aggregate these regions. In practice what I want to do is like having a map of the whole continent showing all countries and producing a map that shows North America and South America.
To me this looks like a pretty common task but I can't find the right function to do it so far. Do I just miss a function or can I simply to it manually?
The rgeos
package provides a number of excellent tools for handling Spatial*
data, that can be used in this case.
For example:
library(rgeos)
regionOfInterest <- gUnion(xx[3,], xx[5,])
This also has the same result, and may be more useful for multiple polygons:
regionOfInterest <- gUnionCascaded(xx[c(3,5), ])
The result from plot(regionOfInterest)
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With