[R] adding text to the top corner of a lattice plot

Gabor Grothendieck ggrothendieck at gmail.com
Fri Dec 17 05:26:08 CET 2010


On Thu, Dec 16, 2010 at 11:12 PM, Rajarshi Guha <rajarshi.guha at gmail.com> wrote:
> Hi, I have a series of lattice plots which I am arranging in a 2x2
> grid via print:
>
> print(p.preds, split=c(1,1, 2,2), more=TRUE)
> print(p.comp, split=c(2,1,2,2), more=TRUE)
> print(p.bw, split=c(1,2,2,2), more=FALSE)
>
> What I'd like to have is a letter (A, B, ...) in the top corner of
> each plot. While panel.text lets me add text anywhere within a plot, I
> can't seem to workout how I could put some text in the top left
> corner, say, of the whole plotting region.
>


Try this using the built in data frame BOD:

library(lattice)
library(gridExtra)
pnl <- function(..., mark) {
	panel.xyplot(...)
	grid.text(mark, unit(.1, "npc"), unit(.9, "npc"))
}
fo <- demand ~ Time
grid.arrange(nrow = 2,
	xyplot(fo, BOD, mark = "A", panel = pnl),
	xyplot(fo, BOD, mark = "B", panel = pnl),
	xyplot(fo, BOD, mark = "C", panel = pnl)
)


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list