[R] Spacing between lattice panels

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue May 6 16:06:48 CEST 2008


On 5/6/08, Richard.Cotton at hsl.gov.uk <Richard.Cotton at hsl.gov.uk> wrote:
> I'm trying to set up a lattice plot with two y-axes for each panel.  (Yes,
>  I know that multiple y-axes are generally a bad idea; the graph is for
>  someone else and they want it that way.)  I've used a custom
>  yscale.component in xyplot to achieve this:
>
>  myyscale.component <- function(...)
>  {
>   ans <- yscale.components.default(...)
>   ans$right <- ans$left
>   foo <- ans$right$labels$at
>   ans$right$labels$labels <- as.character(10*foo)
>   ans
>  }
>
>  xyplot(Sepal.Length ~ Petal.Length| Species, data = iris, scales =
>  list(y=list(relation="free", alternating=3, rot=0)),
>  yscale.component=myyscale.component)
>
>  The problem is that the panels are too close together.  This appears to be
>  because (according to the help documentation) xyplot ignores the
>  alternating argument when relation is not "same".  I presume that manually
>  setting some plotting parameters with trellis.par.set() will allow me to
>  adjust the spacing between the panels, though I can't figure out which
>  ones to change.
>
>  Is there a way to get lattice to properly space the panels,

No.

> or failing that, how do I manually space them?

The space between panels can be controlled using the 'between'
argument. You additionally need some space at the right, for which you
need to set a width component. E.g.,

xyplot(Sepal.Length ~ Petal.Length| Species, data = iris,
      scales = list(y=list(relation="free", alternating=3, rot=0)),
      yscale.component=myyscale.component,
      between = list(x = 2),
      par.settings = list(layout.widths = list(right.padding = 5)))

The full list of components of 'layout.widths' is given by

names(trellis.par.get("layout.widths"))

-Deepayan



More information about the R-help mailing list