[R-sig-Geo] Problem with plotting overlaid maps
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Wed Dec 10 14:07:09 CET 2014
A general piece of advice: always test run your script in an EMPTY R
session (e.g., R --vanilla) before posting.
Below, g1 is unknown; if replaced with g2 the script runs, at least.
On 12/10/2014 01:39 PM, Agustin Lobo wrote:
> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Edzer Pebesma, Co-Editor-in-Chief Computers & Geosciences
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20141210/60d848c9/attachment.bin>
More information about the R-sig-Geo
mailing list