[R-sig-Geo] Fill color in first plotted spatial object lost when writing plot to postscript
Lyndon Estes
lyndon.estes at gmail.com
Fri Mar 7 21:29:59 CET 2014
Dear List,
I am trying to create some maps with postscript, which start with a
base map (of Africa, with grey fill, or with a raster with a single
grey color for all non-NA pixels), and then have a raster that
partially covers the area plotted using a divergent color scheme. The
grey background helps show the color scheme more effectively. This
works fine with the pdf and png functions, but for some reason that I
have yet to figure out does not work when using postscript. The
following toy code demonstrates the problem:
library(raster)
r <- raster(xmn = 0, xmx = 1, ymn = 0, ymx = 1)
res(r) <- 0.1
r[] <- 1
r2 <- raster(xmn = 0, xmx = 1, ymn = 0, ymx = 1)
res(r2) <- 0.1
r2[] <- sample(1:20, ncell(r2), replace = TRUE)
r2[1:(ncol(r2) * (nrow(r2) / 2))] <- NA
# Produces grey background, as desired
png("testfig.png", height = 400, width = 400)
plot(r, col = "grey", legend = FALSE)
plot(r2, add = TRUE)
dev.off()
# Background is white
postscript("testfig.eps", height = 4, width = 4, horizontal = FALSE,
colormodel = "rgb")
plot(r, col = "grey", legend = FALSE)
plot(r2, add = TRUE)
dev.off()
Any pointers on why this is happening, or a reference to the correct
listserv, will be much appreciated. My sessionInfo() follows, and I
am using OS X 10.7.5 (this could be a mac issue I guess).
Thanks, Lyndon
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ncdf4_1.10 TeachingDemos_2.9 xtable_1.7-1 zyp_0.10-1
Kendall_2.2
[6] rgeos_0.3-3 rgdal_0.8-16 raster_2.2-12 sp_1.0-14
loaded via a namespace (and not attached):
[1] boot_1.3-9 grid_3.0.2 lattice_0.20-23 tools_3.0.2
More information about the R-sig-Geo
mailing list