rshapefilergooglemaps

Plot areas on RGoogleMaps


I have a shapefile with regions with polygons, and can successfully use PlotOnStaticMap like this:

#Map <- GetMap.bbox(bb$  #Just to show I read "Map" here
shp_0 <- rgdal::readOGR(dsn="dir", layer="TheLayer")
shp_1 <- shp_0@polygons[[i1]]  # where i1=the region I'm looking at
shp_2 <- shp_1@Polygons[[i2]]  # where i2=the polygon I want to plot
tbl_coords_i2 <- data.frame(shp_2@coords)
tbl_coords_i2$color <- colors()[33]  # red
tmp <- PlotOnStaticMap(lat=tbl_coords_i2$X2, lon=tbl_coords_i2$X1, cex=0.5, pch=15, col=tbl_coords_i2$color, MyMap=Map, add=FALSE, NEWMAP=FALSE, FUN=points)

But what I really want is to plot the areas filled with red, like this:

tmp <- PlotPolysOnStaticMap(polys=shp_2, col=colors()[33], MyMap=Map, border = NULL, lwd=0.25, add=FALSE, NEWMAP=FALSE)

But that gives the error "Error in polys[, "Y"] : object of type 'S4' is not subsettable" How should this be done instead?

Sorry for not providing reproducible code.

Thank you very much.

/Chris

Update: I just realized that the "shp" in PlotPolysOnStaticMap(shp) should be a dataframe with the columns "X" and "Y", i.e. not a shapefile as I previously assumed.

Update 2: Even though I use "border=NA", I get the red polygons with black borders. Anyone know how to get rid of the borders?


Solution

  • For the benefit of others, I here present the workaround I found: I printed "PlotPolysOnMap" and pasted it into my own function "PlotPolysOnMap2". Then in the new function (not shared), I manually set border=NA (it was border=border). Then the polygons were plotted without lines around them. This "ugly fix" probably upsets the programmers more skilled than I am, but I needed to finish today...

    /Chris