[R] How to set the parameters in Trellis Graphics (by Lattice package)

Felix Andrews felix at nfrac.org
Tue Jul 29 15:00:49 CEST 2008

On Tue, Jul 29, 2008 at 5:37 PM, G.H. Zuo <ghong.zuo at gmail.com> wrote:
> Dear R users
> I plot the trellis graphics by using the lattice package.  Everything is
> OK.  Now, I want set
> some parameters of the trellis graphics.
> 1. The tick label site.  By default, only two tick labels had been output in
> x-axis of my plot.
> I want output four or five tick labels.  In the traditional graphics system,
> it will be very easy.
> Just not output the axis in plot by use the parameter xaxt="n", and then
> used axis to add
> the axis.  But it seem useless in the grid graphics system.  Then how can I
> do it?

You would generally use scales=list(ticks=5) or scales=list(x=list(ticks=5)).
See the entry for "scales" in ?xyplot
However, the default (suggested) number of ticks is 4 or 5, so there
may be something odd about your case. How about a reproducible

> 2. How to change the margin of the figure?

Why do you want to do that? Grid graphics automatically allocates
enough space for the objects to be displayed. If you really want to,
there are ways to do it, but I suggest you do not. You are more likely
looking for the "aspect" argument.

> 3. Can I change the style of the figure like par in traditional system.  For
> example, I want
> change all the fontface into bold.  Now, I must change the fontface for
> every item by using
> command trellis.par.set() like this:
> trellis.par.set(list(par.xlab.text = gpar(font = 2),
>                         par.ylab.text = gpar(font = 2),
>                         axis.text = gpar(font = 2),
>                         add.text = gpar(font=2)
>                   ))
> is there a method to change this parameter in one time, like par(font=2)

You can try trellis.par.set(fontsize=list(text=14)) which is similar.
Otherwise you could write a function to set the font parameters;
this could be modified from latticeExtra::custom.theme

> thanks
> G.H.Zuo
>        [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org 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.

Felix Andrews / 安福立
PhD candidate
Integrated Catchment Assessment and Management Centre
The Fenner School of Environment and Society
The Australian National University (Building 48A), ACT 0200
Beijing Bag, Locked Bag 40, Kingston ACT 2604
3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8

More information about the R-help mailing list