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

Agustin Lobo alobolistas at gmail.com
Wed Dec 10 14:49:17 CET 2014


(sorry for the g1 issue, g2 can be used as it is the same extent)
It works for me as well, but when you resize the graphic window  the
map gets distorted. Close
the graphic window before the second part and resize to a rectangle
with much shorter height than length. Does the map keep with its correct shape?
Not for me, while it does with the first option.
Tried before within and outside RStudio

Agus



On Wed, Dec 10, 2014 at 2:07 PM, Edzer Pebesma
<edzer.pebesma at uni-muenster.de> wrote:
> 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
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list