[R-sig-Geo] Problem with plotting overlaid maps

Agustin Lobo alobolistas at gmail.com
Wed Dec 10 13:39:36 CET 2014


I have a problem plotting a raster layer with its legend overlaid on
a GM map. I can circunvent the problem (see below), but then
I get another problem: the resulting map has a geometry that is dependent
upon the geometry of the window. Is there any solution?

This is what I do:

require(rgdal)
require(raster)
require(dismo)
require(colorspace)

colores <- rev(heat_hcl(9,c=c(80,30), l=c(30,90),
power=c(1/5,1.3),alpha = 0.75))
system("wget https://dl.dropboxusercontent.com/u/3180464/hcL1G2.tif",intern=TRUE)
g2 <- raster("hcL1G2.tif")

migmap <- gmap(x = g1, type = "hybrid", zoom = 5)
g2GM <- projectRaster(from = g2, crs = CRS("+init=epsg:3857"))
g2GM[g2GM<0] <- 0


#' Display without legend: no problems but no legend...
plot(migmap)
plot(log10(g2GM),zlim=c(1,5),col=colores, breaks=seq(1,5,by=0.5),
     legend=FALSE, add=TRUE)
#' The map is not distorted (shape independent of window geometry)

#' with legend we must do it this way
plot(log10(g2GM),zlim=c(1,5),col=colores, breaks=seq(1,5,by=0.5),
     legend=TRUE,axes=FALSE)
plot(migmap,add=TRUE)
plot(log10(g2GM),zlim=c(1,5),col=colores, breaks=seq(1,5,by=0.5),
     legend=FALSE, add=TRUE)
#' the map gets distorted depending upon de geometry of the window


Thanks,

Agus



More information about the R-sig-Geo mailing list