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 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? 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. 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") > 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)and the background will change. thanks, -Michael -- Michael Friendly friendly at yorku.ca York University http://www.math.yorku.ca/SCS/friendly.html Psychology Department 4700 Keele Street Tel: (416) 736-5115 x66249 Toronto, Ontario, M3J 1P3 Fax: (416) 736-5814
ripley@stats.ox.ac.uk
2002-Dec-06 18:51 UTC
[R] Controlling graphics parameters in lattice
On Fri, 6 Dec 2002, 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 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?Both. Try trellis.par.set("fontsize", list(default=12)) but it is a bug in the grid package.> As well, I'm confused about why the following has no effect > on the background (from a fresh start): > > > library(lattice)You need to open the device whose background you are trying to change: trellis.device()> > trellis.par.set("background", "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) > > and the background will change.That should be detected (no trellis device open) and give an error or open a device. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595
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] 10I 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