[R-sig-Geo] projection of ggmap:get_map() output

Oscar Perpiñan oscar.perpinan at upm.es
Wed May 7 14:07:44 CEST 2014


Hi,

> As far as I can tell, "levelplot() + layer()"
> or "spplot() + layer()"
> do not check correspondence of the proj4string of the operands on both sides of
> the +. Actually, both commands totally ignore any CRS information.
> This is why we've got into this mess and must be aware of providing consistent layers.

"layer" and "+.trellis" are functions of the latticeExtra package that
modify the panel function of a trellis graphic, for example, the ones
produced by spplot or rasterVis::levelplot. Of course, they don't know
anything about projections. They only display the graphical result of
another function.

Note that "+ layer()" is equivalent to "sp.layout" or modifying
directly the panel function. Some code to explain it better:

library(sp)
library(lattice)
library(latticeExtra)

data(meuse)
coordinates(meuse) <- ~x+y

## These three methods produce the same result:

## Standard lattice method: modification of the panel function
spplot(meuse["ffreq"], panel=function(...){
    panel.pointsplot(...)
    sp.text(c(180500, 329900), 'Meuse')
})

## sp.layout method
l1 <- list("sp.text", c(180500, 329900), 'Meuse')
spplot(meuse["ffreq"], sp.layout=list(l1))

## latticeExtra method: +.trellis and layer
spplot(meuse["ffreq"]) + layer(sp.text(c(180500, 329900), 'Meuse'))

These three methods do not use CRS information. Review the first
example of the spplot help page and you will find that the components
of the sp.layout do not use CRS information. It is the user's
responsibility to make correct use of the corresponding functions.

On the other hand, you can use +.trellis without layer to combine two
trellis objects. For example, levelplot + spplot, or spplot + spplot,
etc. Therefore, in section 2.3 of your RPubs, when you say that
"layer() does not work with raster layers, therefore cannot use the
rgmaprgbGM object.", you can try this:

levelplot(rgmaprgbGM[[3]], margin = FALSE, par.settings = GrTheme) +
spplot(NWEurGM, zcol = "NAME", fill = "transparent", col = "yellow",
xlim = c(extent(rgmaprgbGM)@xmin, extent(rgmaprgbGM)@xmax), ylim =
c(extent(rgmaprgbGM)@ymin, extent(rgmaprgbGM)@ymax),
    colorkey = FALSE)

Best,

Oscar.



More information about the R-sig-Geo mailing list