Hi all,

Briefly, running the following code will not produce a single grey ring, as
would be expected. The first three raster layers all stack up neatly, but
the 4th and subsequent raster layers are all shifted/skewed to the right.

It appears that the plotting engine loses track of the fact that some space
in the original plot was allocated to a legend, and just begins plotting as
if a wider canvas were available to it.

I'm not sure whether this is ultimately an issue with raster or sp or
something else, which is why I'm noting it here on R-sig-geo. (I'm also
fully aware that there are other and better ways to add several raster
layers to a plot, but still think the following behavior qualifies as a bug
that I ought to report.)

  library(maptools) ## Only needs to be installed for example data
  library(raster)
  library(rgeos)

  ## Create an example raster
  p <- shapefile(system.file("shapes/co37_d90.shp", package="maptools"))
  p <- p[31,]  ## A tall narrow county polygon
  pr <- gDifference(gBuffer(p, width=.01), p)
  r <- rasterize(pr, raster(extent(pr), ncol=100, nrow=100))

  ## These three are properly registered on one another
  plot(r, col="yellow", legend=FALSE)
  plot(r, col="green", legend=FALSE, add=TRUE)
  plot(r, col="grey", legend=FALSE, add=TRUE)
  ## All subsequent "layers" are improperly shifted/skewed to right
  plot(r, col="yellow", legend=FALSE, add=TRUE)
  plot(r, col="blue", legend=FALSE, add=TRUE)
  plot(r, col="red", legend=FALSE, add=TRUE)
  plot(r, col="grey20", legend=FALSE, add=TRUE)
  ## Following the above, SpatialPolygons are also shifted/skewed
  plot(p)



My session info, in case it matters, is:

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rgdal_0.8-14  rgeos_0.3-2   raster_2.1-66 sp_1.0-14

loaded via a namespace (and not attached):
[1] compiler_3.0.2  grid_3.0.2      lattice_0.20-24 tools_3.0.2

	[[alternative HTML version deleted]]

