[R-sig-Geo] Strategy to crop margins in map by spplot()?

Brian Oney zenlines at gmail.com
Wed Aug 24 14:35:37 CEST 2011


Hi Matthieu,
I was afraid of something like that. However, I see a difference with my 
plots.

Taking your code:

library(maptools)
library(lattice)

data(wrld_simpl) # the meuse data set has a nice way to create polygons, 
but no matter, the behavior is not different for different types of 
vector data
# x11(type="Xlib") # couldn't get this to work, but oh well
spplot(wrld_simpl, "SUBREGION")

cut.val <- -5 ### Just to force it.
theme.novpadding <-
    list(layout.heights =
         list(top.padding = cut.val,
              main.key.padding = cut.val,
              key.axis.padding = cut.val,
              axis.xlab.padding = cut.val,
              xlab.key.padding = cut.val,
              key.sub.padding = cut.val,
              bottom.padding = cut.val),
         layout.widths =
         list(left.padding = cut.val,
              key.ylab.padding = cut.val,
              ylab.axis.padding = cut.val,
              axis.key.padding = cut.val,
              right.padding = cut.val))

spplot(wrld_simpl, "SUBREGION",    par.settings = theme.novpadding)

Don't forget that spplot parameters: xlim and ylim are derived by 
default from the bounding box (xlim = bbox(obj)[1, ], ylim = 
bbox(obj)[2, ], thereby retaining the aspect ratio).
Therefore, if you have a "landscape"-oriented object, and you try to 
plot/save as .png with png() parameters where width is less that height 
(i.e. some ratio different than you aspect ration), R will do exactly 
what you tell it to, giving you big margins.

There are many ways to skin a cat. I would check the latter, before 
trying the former. R and the lattice plot functions have pretty good 
default values and for good reason.

hth,
Brian

On 8/24/2011 2:16 PM, Matthieu Stigler wrote:
> library(maptools)
> library(lattice)
>
> data(wrld_simpl) #sorry, this is so slow, but is the only polygon 
> shapefile available by default I think?
> x11(type="Xlib") #should be slightly faster
> spplot(wrld_simpl, "SUBREGION")
>
> theme.novpadding <-
>    list(layout.heights =
>         list(top.padding = 0,
>              main.key.padding = 0,
>              key.axis.padding = 0,
>              axis.xlab.padding = 0,
>              xlab.key.padding = 0,
>              key.sub.padding = 0,
>              bottom.padding = 0),
>         layout.widths =
>         list(left.padding = 0,
>              key.ylab.padding = 0,
>              ylab.axis.padding = 0,
>              axis.key.padding = 0,
>              right.padding = 0))
> spplot(wrld_simpl, "SUBREGION",    par.settings = theme.novpadding)



More information about the R-sig-Geo mailing list