Skip to content
Prev 66527 / 398503 Next

Lattice : factor levels in the margins

Hi
Yves Brostaux wrote:
Here's one approach, using trellis.focus() and grid.text().  This 
particular example is obviously hand-tuned to the example data set, but 
it shouldn't be too hard to generalise.  I don't think you can do this 
via a panel function because output is clipped to the current panel for 
panel functions (Deepayan Sarkar may be able to confirm or deny that).

# "standard" dotplot
dotplot(variety ~ yield | year * site, data=barley)

# Customised version
library(grid)
# lattice plot without strips
dotplot(variety ~ yield | year * site, data=barley,
         strip=FALSE)
# move to panel (1, 6) and turn clipping off so can draw outside panel
trellis.focus("panel", 1, 6, clip.off=TRUE, highlight=FALSE)
# draw factor label 2 lines above the top of the panel
grid.text("1932", y=unit(1, "npc") + unit(2, "lines"))
# move to next panel, repeat ad nauseam
trellis.focus("panel", 2, 6, clip.off=TRUE, highlight=FALSE)
grid.text("1931", y=unit(1, "npc") + unit(2, "lines"))
grid.text("Waseca", x=unit(1, "npc") + unit(1, "lines"), rot=90)
trellis.focus("panel", 2, 5, clip.off=TRUE, highlight=FALSE)
grid.text("Crookston", x=unit(1, "npc") + unit(1, "lines"), rot=90)
trellis.focus("panel", 2, 4, clip.off=TRUE, highlight=FALSE)
grid.text("Morris", x=unit(1, "npc") + unit(1, "lines"), rot=90)
trellis.focus("panel", 2, 3, clip.off=TRUE, highlight=FALSE)
grid.text("University Farm", x=unit(1, "npc") + unit(1, "lines"), rot=90)
trellis.focus("panel", 2, 2, clip.off=TRUE, highlight=FALSE)
grid.text("Duluth", x=unit(1, "npc") + unit(1, "lines"), rot=90)
trellis.focus("panel", 2, 1, clip.off=TRUE, highlight=FALSE)
grid.text("Grand Rapids", x=unit(1, "npc") + unit(1, "lines"), rot=90)

Paul