I have a shapefile composed of polygons (sample here), many of which have holes in them. I cleaned the polygon layer in GRASS. After cleaning, QGIS's 'Check Geometry Validity' tool returned no errors. I then loaded the shapefile to R as follows:
polys <- readOGR(dsn=path.expand("U:/FandR"), layer="polygon")
polysCRS<- spTransform(polygons, CRS("+init=epsg:32717"))
polysCRS@data$id=rownames(polysCRS@data)
polysCRS.points = fortify(polysCRS, region="id")
polysCRS.df = join(polynsCRS.points, polysCRS@data, by="id")
Unfortunately, upon plotting, I can see that the holes in the polygons are filled.
#plot the polygons!
ggplot(polysCRS.df)+
aes(long,lat,group=group)+
geom_polygon(fill="#006600")+
geom_path(color="white") +
coord_equal()
Here is an image of a portion of my polygon plot, zoomed in to see the worst portion of the plot.
How can I correct this mistake in my loaded SpatialPolygonsDataFrame?
Best Answer
You can now use package sf and the development version of ggplot2 (e.g. devtools::install_github('tidyverse/ggplot2')).