[R] lattice: adding text between grouped panels?

Deepayan Sarkar deepayan at stat.wisc.edu
Tue Jan 20 17:40:56 CET 2004


On Tuesday 20 January 2004 04:14, Wolfram Fischer wrote:
> How one can add a text (e.g. the labels of an axis)
> in a space between grouped panels which was created
> by using the argument ``between''?
>
> Example:
> 	data(barley)
> 	dotplot(variety ~ yield | site * year, data=barley,
> 		between=list(x=c( 0, 0, 6 ))
> How to add labels for the y axis in the space in the middle?

Formally, there's no mechanism to do that. However, most reasonable usage can 
be achieved by the panel function, e.g. (to add a y-axis tick and label at 
the mean y-value):

panel = function(x, y, ...) {
    panel.xyplot(x, y, ...)
    grid.yaxis(at = mean(y))
}

Normally, this would not work because all graphical output produced by the 
panel function is 'clipped', i.e., anything falling outside the panel is not 
drawn. This can be controlled by the setting

> trellis.par.get("clip")
$panel
[1] TRUE

$strip
[1] TRUE


So you need to do something like 

> lset(list(clip = list(panel = FALSE)))

before calling xyplot (or whatever). Of course, turning clipping off has the 
disadvantage that unintended things can happen. Most panel functions are 
safe, but some are not (like panel.abline).


Just in case you missed it, there's a much safer way to add customized tick 
marks and labels to each panel, using the scales argument. From ?xyplot, 


  scales: list determining how the x- and y-axes (tick marks and

          [...]

          at: location of tick marks along the axis (in native
          coordinates), or a list as long as the number of panels
          describing tick locations for each panel.

          labels: Labels (strings or expressions) to go along with
          'at'. Can be a list like 'at' as well.

But this may not be what you want.

Hth,

Deepayan




More information about the R-help mailing list