[GIS] Remove lines from inside a polygon (shapefile) in r

ggmapggplot2polygonrsp

enter image description hereI have this code which prints the Galápagos Islands. But inside the islands, there are lines that I want to get rid off. How is this possible in R?

library(rgdal)
library(ggplot2)

URL <- "https://osm2.cartodb.com/api/v2/sql?filename=public.galapagos_islands&q=select+*+from+public.galapagos_islands&format=geojson&bounds=&api_key="
fil <- "gal.json"
if (!file.exists(fil)) download.file(URL, fil)
gal <- readOGR(fil, "OGRGeoJSON")    
gal_map <- fortify(gal)
ggplot() + 
  geom_map(map=gal_map, data=gal_map, aes(x=long, y=lat, map_id=id)) + 
  coord_equal()

Look at the picture: I don't want to show these lines (all of them).

Best Answer

You can aggregate the polygons and then disaggregate to the 182 individual islands.

URL <- "https://osm2.cartodb.com/api/v2/sql?filename=public.galapagos_islands&q=select+*+from+public.galapagos_islands&format=geojson&bounds=&api_key="
fil <- "gal.json"
if (!file.exists(fil)) download.file(URL, fil)

library(rgdal)
gal <- readOGR(fil, "OGRGeoJSON")   

library(raster)
library(rgeos)

a <- aggregate(gal)
b <- disaggregate(a)

plot(b, col=sample(rainbow(length(b))))