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
Question with spplot for publication
4 messages · Ziyu Ma, Roger Bivand, Jon Olav Skoien
On Fri, 22 Aug 2014, 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.
Typically, you use the sp.layout= argument to spplot. This takes a list of
extra information to be plotted. However, spatial polygons are thought of
as filled, so you should coerce then to SpatialLines first:
spl <- list("sp.lines", as(my_polys, "SpatialLines"), lwd=2, col="white")
then
spplot(..., sp.layout=spl)
or a list of lists if there are other kinds of information to add.
Hope this helps,
Roger
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 at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no
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 at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Thanks Jon and Roger! The panel function worked effortlessly! And I learned a lot from your codes. Cheers, Ma Ziyu Ma PhD Student Ecoinformatics & Biodiversity, Department of Bioscience, Aarhus University Ny Munkegade 114, DK-8000 Aarhus C, Denmark On Fri, Aug 22, 2014 at 9:45 AM, Jon Skoien <jon.skoien at jrc.ec.europa.eu> wrote:
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 at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo