Re: [R] Changing graphics height when using grid and lattice

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Thu, 28 Jun 2007 15:24:41 -0700

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



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 29 Jun 2007 - 00:08:52 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 29 Jun 2007 - 01:32:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.