R maptools o paquete rgdal: ¿cómo llenar el exterior de un polígono?

I am trying to plot a shapefile of polygons on top of another shapefile that already has colored polygons using R, and I am working with maptools and rgdal. I want to clip the bottom shapefile (which has multiple polygons) to the area delimited by the top shapefile, which has four polygons (i think). I know how to fill the inside of the top polygon, of course, by using the col= command within plot(). But what I want to do is fill the outside of the top polygon white, and leave the bottom colored polygons visible through the inside of the top polygons. I will redraw the boundaries of the bottom polygons after I am able to do this. I am using R 2.13.2 and the latest editions of maptools and rgdal and all of their dependencies on a Windows 7 machine.

I have code that depends on these shapefiles: ftp://ftpext.usgs.gov/pub/er/wi/la.crosse/McKann/bcr%20arcinfo%20files/

library(maptools)

sm=readShapeSpatial('states.shp')
pm=readShapeSpatial('province.shp')

library(rgdal)

rgm=readOGR(dsn=wd,layer='gwwa_new_range_5Jul11')
rgm2=spTransform(rgm,CRS(proj4string(sm2)))
plot(c(-120,-61),c(35,55),type='n',axes=F,bty='n',xlab='',ylab='', main=sp)
plot(sm,col=c('red','green','yellow'),add=T)##us states
plot(pm,col=c('red','green','yellow'),add=T)##canadian provinces
plot(rgm2,lwd=2,add=T,border='blue')##gives the range of this bird

I can make the inside of the range map a color

plot(rgm2,add=T,col='blue')

but what i want to do is make the outside white (so I can draw the states and province boundaries over this afterwards), and keep the inside transparent, so I can see the colors of the states and provinces within the range.

Please let me know if you need more info and thanks in advance for any help. Maybe there is an easier way...

preguntado el 10 de marzo de 12 a las 00:03

wd is not defined in your example -

and sm2 is not defined either -

wd is the working directory where the shapefiles are stored (will be different from my location if you download the data and work with it). sm2 can be changed to sm. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.