[R-sig-Geo] Harmonizing the sizes of side-by-side spplots

David Rossiter rossiter at itc.nl
Thu May 3 17:21:05 CEST 2012


I often want to display two or more maps of the same area, prepared with spplot, side-by-side, but the sizes of the map do not match if (1) a legend is printed and (2) the width of the text in the legend is different. For example:

> require(gstat)
> data(jura)
> coordinates(jura.grid) <- ~ Xloc + Yloc
> gridded(jura.grid) <- T
>  fullgrid(jura.grid) <- T
> print(, split=c(1,1,2,1), more=T)
> p1 <- spplot(jura.grid, zcol="Landuse", col.regions=terrain.colors(4))
> p2 <- spplot(jura.grid, zcol="Rock", col.regions=bpy.colors(5))
> require(lattice)
> print(p1, split=c(1,1,2,1), more=T)
> print(p2, split=c(2,1,2,1), more=F)

Here, since the longest name of the rock types is longer than that of the landuse, the rock type map is smaller, to make room within the box for the legend.

(The same hapens if plotting kriging predictions next to their variances, if the numeric precision is not the same.)

I can get around the problem by adjusting the position within the box for the larger map:

print(p1, position=c(0.04,0.04,.96,.96), …)

but this (1) requires a manual assessment (maybe I could do it automatically by looking at the legend categories?) and (2) seems a clumsy way to do this. I have waded through the

I've tried to use the panel.height and panel.width arguments to print.trellis, but without success:

> str(p.width <- lattice.getOption("layout.widths")$panel)
List of 3
 $ x    : num 1
 $ units: chr "null"
 $ data : NULL
> p.width <- list(0.9,"null",NULL)

But this (1) does not seem to affect the plots, (2) would probably only affect the whole panel, not just the map. I need to set the size of the map and legend separately.

I tried to present these as side-by-side levelplots, but since the levels are not the same this fails also:

> p3 <- spplot(jura.grid[c("Landuse","Rock")])
Error in stack.SpatialPointsDataFrame(as(data, "SpatialPointsDataFrame"),  :
  all factors should have identical levels

Thanks for any help,

D G Rossiter
Senior University Lecturer
Faculty of Geoinformation and Earth   Observation Science
Universiteit Twente.
Enschede (NL)


Faculty of Geo-Information Science and Earth Observation (ITC)
University of Twente
Chamber of Commerce: 501305360000

E-mail disclaimer
The information in this e-mail, including any attachments, is intended for the addressee only. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or action in relation to the content of this information is strictly prohibited. If you have received this e-mail by mistake, please delete the message and any attachment and inform the sender by return e-mail. ITC accepts no liability for any error or omission in the message content or for damage of any kind that may arise as a result of e-mail transmission.



More information about the R-sig-Geo mailing list