1

I retrieved a map to plot points on using the (RgoogleMaps) package using the following Rcode:

library(RgoogleMaps)
lat = c(-30.3022,-30.5000,-33.48569)
lon = c(153.1189,151.6500,145.5316)
center = c(mean(lat), mean(lon))
zoom <- min(MaxZoom(range(lat), range(lon)))
mymap <- GetMap(center=center, zoom=zoom, maptype= "terrain", destfile = "MyTile1.png")

I've also successfully plotted my 3 points on that map using:

NewMap <- PlotOnStaticMap(mymap, lat = c(-30.3022,-30.5000,-32.24300),  
      lon = c(153.1189,151.6500,148.6019), destfile = "MyTile1.png", cex=1.5,pch=20, 
      col=c('red', 'purple', 'green'), add=FALSE)       

Now I need to over-lay a grid of Lat-long values, or even just a grid of any type. Any Ideas? I've done some fairly extensive research and it appears that (RgoogleMaps) doesn't have a simple way of doing this.

Thanks, D.A.S.

DASmith
  • 11
  • 1
  • You may need to define a SpatialGrid object. See this nice answer: http://gis.stackexchange.com/questions/88830/overlay-a-spatial-polygon-with-a-grid-and-check-in-which-grid-element-specific-c – Julian Wittische Nov 23 '15 at 07:43

1 Answers1

1

You can use dismo::gmap for this. It returns a google map as a RasterLayer and you can use it to overlay Spatial* objects (sp package), e.g. SpatialPolygons or SpatialLines, and Raster* objects (raster objects), or just use points or lines

library(dismo)
lat = c(-30.3022,-30.5000,-33.48569)
lon = c(153.1189,151.6500,145.5316)
xy <- cbind(lon, lat)

g <- gmap(xy, lonlat=TRUE, scale=2)
plot(g, interpolate=TRUE)
points(xy, col='red', pch=20)
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63