[R-sig-Geo] spplot with two rasters

Dylan Beaudette dylan.beaudette at gmail.com
Mon Mar 17 17:51:03 CET 2008


On Wednesday 12 March 2008, Roger Bivand wrote:
> On Wed, 12 Mar 2008, Dylan Beaudette wrote:
> > On Thursday 06 March 2008, Thomas Adams wrote:
> >> Dylan,
> >>
> >> I think a solution using GRASS can be found on pages 110-111 of "Open
> >> Source GIS: A GRASS GIS Approach", 3rd Ed. The same material is covered
> >> in the 2nd Ed. as well, where you use r.mapcalc to combine two rasters
> >> and judicious use of MASKs; a conditional statement in r.mapcalc is the
> >> key.
> >>
> >> Regards,
> >> Tom
> >
> > Hi Tom,
> >
> > Thanks for the suggestion. This works, but we were hoping to make the
> > plot in R-- as the PDF output is hard to match with GRASS alone. I
> > suppose I will just have to try using two rasters with spplot() and see
> > what happens.
>
> The problem is that customising a panel to insert an image probably means
> writing just that, customised panels, and spplot() essentially does that
> already. You could look at Chapter 5 in Paul Murrell's book, to see how to
> insert grid output into lattice output (to try to put an image as a
> backcloth, but there is no example for this case - the example is for
> adding a location position.
>
> My guess would be that if you are only displaying a single panel, you will
> find it easier to use base graphics, and simply say image() twice, and use
> legend() (or legend.krige() from geoR).
>
> Roger

Thanks for the tips Roger. I think that in this case it will be simplest to 
use multiple calls to image().

Cheers,

Dylan


> > Cheers,
> >
> > Dylan
> >
> >> Dylan Beaudette wrote:
> >>> On Tuesday 04 March 2008, Edzer Pebesma wrote:
> >>>> I find it hard to imagine how you want to plot two raster files on top
> >>>> of each other. Do you want some form of transparency? If it is just
> >>>> one overlaying the other, you could use overlay to find out which
> >>>> cells in raster 1 to replace with those in raster 2 before plotting.
> >>>> --
> >>>> Edzer
> >>>
> >>> Hi Edzer,
> >>>
> >>> I generally agree that plotting one raster file "over" another raster
> >>> file would be of little use. In this case, one of the raster files (the
> >>> interesting one) has been masked with nodata, such that it only really
> >>> covers about 30% of the region of interest. The other raster is just
> >>> contextual data, and thus would be useful to plot "behind" the first
> >>> raster.
> >>>
> >>> Ideas?
> >>>
> >>> Dylan
> >>>
> >>>> Dylan Beaudette wrote:
> >>>>> Hi,
> >>>>>
> >>>>> Is it possible to plot two raster images using spplot() in a manner
> >>>>> similar to:
> >>>>>
> >>>>> pts <- list("sp.points", points_file, pch = 4, col = "black",
> >>>>> cex=0.5) spplot(raster_file, zcol="elev.pred", sp.layout=list(pts))
> >>>>>
> >>>>> Note that one of the raster images is an aerial photo, used only for
> >>>>> context, while the second one is one with interesting z-values. The
> >>>>> second raster is masked and thus does not cover the entire region.
> >>>>>
> >>>>> Thanks,
> >>>>>
> >>>>> Dylan



-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341




More information about the R-sig-Geo mailing list