[R] lattice: adding text between grouped panels?

Wolfram Fischer wolfram at fischer-zim.ch
Thu Jan 22 09:39:38 CET 2004


--- In reply to Deepayan Sarkar: ---
>Date:    20.01.04 10:40 (-0600)

Thank you again for your very helpful and inspiring answer!
Some additional questions will follow below.

> 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).

This good idea seams to work. But:

- How can I determine in which panel I am?
  Principally I could to that by using a strip function.
  But the presence of a strip function allways (?) allocates
  space for the strip(s). How can I determine the panel
  when I don't want to display strips?


> 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.

Thanks for this hint!

When I wanted add labels to each panel group of:

	my.barley <- subset( barley, ! ( site == "Grand Rapids" & year == "1932" ) )

	with( my.barley, dotplot(variety ~ yield | year * site, layout=c(6,2)
		, between=list(x=c(0,6))))


I tried:
	with( my.barley, dotplot(variety ~ yield | year * site, layout=c(6,2)
		, scales=list( rot=0, y=list( relation='sliced'
		, at = rep( list( 1: nlevels( variety ), NULL ), 6 )))))

I used:
- ``sliced'' because there was an error when I did not use it:
	"the at and labels components of scales may not be
	lists when relation = same".
- the at-option to eliminate the yaxis-labels within the panel groups.

I received:
- Several warning messages.
- No axis labels for panel groups with an empty first panel.
- Gigant scales in the second panels of each panel group.

What can I do to:
- Have normal scales in the second panels of each panel group?
- Eliminate the space between the first and the second panel
  in each group.

> Hth,
> 
> Deepayan

Thanks! Wolfram




More information about the R-help mailing list