[R] Controlling graphics parameters in lattice
Deepayan Sarkar
deepayan at stat.wisc.edu
Fri Dec 6 20:28:03 CET 2002
On Friday 06 December 2002 10:37 am, Michael Friendly wrote:
> I'm just starting to work with lattice graphics, and am
> having difficulty understanding how to control various graphic
> parameters (font sizes, etc.). [I'm actually using xyplot
> via plot.effect() in the car package, and would like to be
> able to set some global defaults.]
>
> I read ?xyplot and ?trellis.par.set-- which contains no complete
> list of parameters, just a reference to print(trellis.par.get())
>
> > print(trellis.par.get())
>
> $fontsize
> $fontsize$default
> [1] 10
I get a much longer list.
> I tried
>
> > trellis.par.set("fontsize", 12)
> > data(quakes)
> > Depth <- equal.count(quakes$depth, number=8, overlap=.1)
> > xyplot(lat ~ long | Depth, data = quakes)
> And this crashes the Rgui (Windows, R 1.6.1). Is this a buglet
> or did I do something wrong?
You are doing this wrong. ?trellis.par.set gives an example of usage:
`trellis.par.get' is usually used inside trellis functions to get
graphical parameters before plotting. Modifications by users via
`trellis.par.set' is typically done as follows:
`add.line <- trellis.par.get("add.line")'
`add.line$col <- "red"'
`add.line <- trellis.par.set("add.line", add.line)'
(the assignment in the last line is redundant, sorry about that)
Your example, adapted to look like this, would have been:
fsize <- trellis.par.get("fontsize")
fsize$default <- 12
trellis.par.set("fontsize", fsize)
The point you are missing is the value argument to trellis.par.set should be a
list, even when it has only one component. (I will change trellis.par.set to
complain when value is not a list.)
A slightly easier way to do this is use
lset(list(fontsize = list(default = 12)))
(This becomes useful when the parameter you are changing has many components,
but you are changing only one or two.)
> I then tried
>
> > xyplot(lat ~ long | Depth, data = quakes, scales=list(cex=1.5))
>
> which makes the tick labels larger, but not the axis labels.
That goes into xlab / ylab.
> As well, I'm confused about why the following has no effect
>
> on the background (from a fresh start):
> > library(lattice)
> > trellis.par.set("background", "white")
Same reason. Should be
trellis.par.set("background", list(col = "white"))
or
lset(list(background = list(col = "white"))
> > data(quakes)
> > Depth <- equal.count(quakes$depth, number=8, overlap=.1)
> > xyplot(lat ~ long | Depth, data = quakes)
>
> Only after I've run xyplot once, I can repeat
>
> > trellis.par.set("background", "white")
> > xyplot(lat ~ long | Depth, data = quakes)
Probably has to do with the fact that
trellis.par.get("background")$col is now NULL.
Deepayan
More information about the R-help
mailing list