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. Any pointers would be appreciated -- Rajarshi Guha NIH Chemical Genomics Center
Gabor Grothendieck
2010-Dec-17 04:26 UTC
[R] adding text to the top corner of a lattice plot
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
On Dec 16, 2010, at 11:12 PM, Rajarshi Guha 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.If you are planning on used the internal coordinate system (in terms of max and min of the x and y coordinates or whatever the exact lattice terminology is) which is what panel.text will be expecting, then it is going to depend on the plotting function, arguments, and data .... none of which you have not provided. ( It may also depend on what you mean when your write "the whole plotting region", since that is also a bit ambiguous at the moment) ########>>>>>>>>>> and provide commented, minimal, self-contained, reproducible code.########>>>>>>>> David Winsemius, MD West Hartford, CT