Hi Ma,
You should be able to plot the polygon on top of your raster with a
panel function. Here is an example with the meuse data:
r <- raster(system.file("external/test.grd", package="raster"))
s <- stack(r, r*2)
names(s) <- c('meuse', 'meuse x 2')
spplot(s)
data(meuse.riv)
meuse.sr =
SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)),"meuse.riv")))
spplot(s,
panel = function(x, y, ...) {
panel.gridplot(x, y, ...)
sp.polygons(meuse.sr)
}
)
Is this more or less how you want it?
Cheers,
Jon
On 8/22/2014 9:15 AM, Ziyu Ma wrote:
Dear all,
I miss you guys from GEOSTAT Bergen!
Here's my question: I want to make a map directly from R for my manuscript,
using a raster layer overlaid with spatial polygons as outlines.
Please see the attachment for what I mean: http://1drv.ms/1sYYqPg
I did the upper plot in the attachement using these codes:
NRI = stack(NRI.A,NRI.G) # NRI.A and NRI.G are raster layer names
names(NRI) = c("Angiosperms NRI", "Gymnosperms NRI")
spplot(NRI)
I need to put two rasters together in spplot because I want to use the same
legend scale.
I also want to add the outlines, so that it can look like the Photoshopped
plot in the attachment.
Normally, if not using spplot, I can do this:
plot(NRI.G) # NRI.G is a raster layer
plot(Outlines) # Outlines is a SpatialPolygons object
But how can I do it for both panels in spplot? I think the panels and
titles in spplot are very neat, so it is preferred if there is a straight
forward way to tweak the settings.
Or should I use other functions than spplot? (e.g. try coding the color
scheme of the 2 plots and place them side by side?)
Thank you for the help. I really appreciate those who made R able to
produce publication quality plots.
Cheers,
Ma
Ziyu Ma
PhD Student
Ecoinformatics & Biodiversity,
Department of Bioscience, Aarhus University
Ny Munkegade 114, DK-8000 Aarhus C, Denmark
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo