How can I over-lay a lat-long grid onto a GetMap (RgoogleMaps) in R?

259 views Asked by At

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.

1

There are 1 answers

0
Robert Hijmans On

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)