[R-sig-Geo] Strategy to crop margins in map by spplot()?
Brian Oney
zenlines at gmail.com
Wed Aug 24 13:12:12 CEST 2011
Hi Matthieu,
As spplot is "just" a wrapper for the lattice package. It helps to
know/learn a thing about the lattice package.
The control of graphical parameters in the lattice package is extremely
fine.
Here is one working example changing the layout parameters:
library(sp)
library(lattice) # required for trellis.par.set():
trellis.par.set(sp.theme()) # sets color ramp to bpy.colors()
data(meuse)
coordinates(meuse)=~x+y
## coloured points plot with legend in plotting area and scales:
spplot(meuse, "zinc", do.log = TRUE,
key.space=list(x=0.2,y=0.9,corner=c(0,1)),
scales=list(draw=T))
### Do a bit of exploring in lattice
trellis.pars.save <- trellis.par.get() # for good measure
trellis.pars <- trellis.par.get()
names(trellis.pars)
names(trellis.pars$layout.heights)
layout.height <- trellis.par.get("layout.heights")
names(layout.height)
layout.height$top.padding
layout.height$top.padding <- 0 ### here is where margins etc. can be changed
trellis.par.set(layout.heights = layout.height)
### now try it again
spplot(meuse, "zinc", do.log = TRUE,
key.space=list(x=0.2,y=0.9,corner=c(0,1)),
scales=list(draw=T))
windows() ### open a new plotting device to compare with other plots
### Put it back to the defaults
trellis.par.set(layout.heights = trellis.pars.save$layout.heights)
I recall that sweaving with the lattice package presents some problems,
but can't remember exactly. If there are problems, I would "manually"
insert it i.e.:
<<echo=FALSE,results=tex>>=
### this should work but not so sure.
png(file="graph.png", width = 4, height = 5,units='in',res=900)
spplot(something)
dev.null <- dev.off()
cat("\\includegraphics[width=0.95\\textwidth]{graph}\n\n", sep="")
@
hth,
Brian
More information about the R-sig-Geo
mailing list