Chris, Yes, I think it is a projection issue, as Google maps are in
Mercator projection. Here is an example (dismo::gmap is based on
RGoogleMaps but returns a RasterLayer, which makes things easier).

library(dismo)

e <- extent(c(-122.308247, -122.224433, 47.495551, 47.582025))
r <- raster(e, crs="+proj=longlat +datum=WGS84")
values(r) <- runif(ncell(r))

g <- gmap(r)
r2 <- raster(g)
dim(r2) <- dim(r)
r2 <- projectRaster(r, r2)

plot(g)
plot(r2, add=T, alpha=0.25)


Best, Robert

On Wed, Nov 23, 2011 at 2:50 PM, Chris Fowler <chris@csfowler.com> wrote:

> Dear List,
>
> I have run into a wall trying to use the RgoogleMaps package with a raster
> overlay. The description says the suite of functions can easily be modifies
> to plot raster, but the method escapes me. The code below is run under
>  most recent R and updated packages on Windows 64 bit.
>
> library(RgoogleMaps)
> #My study area
> lats<-c(47.495551, 47.582025)
> lons<-c(-122.308247, -122.224433)
> centerPt<-c(47.538788, -122.26634)
>
> #define an extent object for raster creation
> e <- extent(lons,lats)
> r2 <- raster(e)
> #assign random values for test
> values(r2) <- runif(ncell(r2))
>
> #Get the map from google
> MyMap <- GetMap.bbox(lat=lats,lon=lons, destfile = "Test.png", GRAYSCALE
> =F)
>
> #Plot it
> PlotOnStaticMap(MyMap,lat=lats,lon=lons,destfile="Test.png",
>    NEWMAP=F, zoom=MaxZoom(lats,lons),add=F)
>
> #Now I define a function to plot my raster with modified alpha
> #Ideally this function would be called by a modified PlotRasterOnStaticMap
> #in the same way PlotPolyOnStaticMap currently calls the 'lines' function
> to add an overlay
> plot.raster<-function(r){
>  library(RColorBrewer)
>  col <- brewer.pal(9, 'RdBu')
>  plot(r, ext=extent(r),col=col, alpha=.8,add=TRUE)
> }
> #call my function
> plot.raster(r2)
>
> When I do all this I get my google map with my raster legend to the side,
> but nothing more. Is this a projection issue?
> Not too experienced with using the raster functions, so any tips would be
> appreciated.
>
> Cheers,
>
> Chris
>
>
> Christopher S. Fowler PhD.
> 206.920.1686
> http://csfowler.com
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

