[R] Changing graphics height when using grid and lattice
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Jun 29 00:24:41 CEST 2007
On 6/28/07, Jim Price <price_ja at hotmail.com> wrote:
>
> Hi,
>
> I have recently been playing with the grid package in an attempt to create
> some pages containing multiple lattice plots on the same page. However, when
> I specify a grid layout with different widths, such as:
>
> pushViewport(viewport(layout = grid.layout(1, 2, unit(c(2, 1), "null"))))
>
> the individual graphs do not end up as the same height - which is a feature
> I would prefer to have.
The default "padding" between components of a graph is defined as a
proportion of the plot area. In particular, it's unit(0.01, "snpc"),
which makes it the same on both axes. The problem is that when you
have two grid viewports, unit(0.01, "snpc") may give different
physical length.
One option is to set all paddings to 0, which can be done with
myLatticeSettings <- function()
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)
)
trellis.par.set(myLatticeSettings())
This may not be what you want, so another option is to set the
paddings to something absolute; e.g.
myLatticeOptions <- function()
list(layout.heights =
list(top.padding = list(x = 1, units = "mm", data = NULL),
main.key.padding = list(x = 1, units = "mm", data = NULL),
key.axis.padding = list(x = 1, units = "mm", data = NULL),
axis.xlab.padding = list(x = 1, units = "mm", data = NULL),
xlab.key.padding = list(x = 1, units = "mm", data = NULL),
key.sub.padding = list(x = 1, units = "mm", data = NULL),
bottom.padding = list(x = 1, units = "mm", data = NULL)),
layout.widths =
list(left.padding = list(x = 1, units = "mm", data = NULL),
key.ylab.padding = list(x = 1, units = "mm", data = NULL),
ylab.axis.padding = list(x = 1, units = "mm", data = NULL),
axis.key.padding = list(x = 1, units = "mm", data = NULL),
right.padding = list(x = 1, units = "mm", data = NULL))
)
lattice.options(myLatticeOptions())
I'm not particularly attached to the "snpc" solution, so I may change
them at some point.
-Deepayan
More information about the R-help
mailing list