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

Rajarshi Guha rajarshi.guha at gmail.com
Fri Dec 17 06:07:17 CET 2010


On Thu, Dec 16, 2010 at 11:26 PM, David Winsemius
<dwinsemius at comcast.net> wrote:
>
> 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.
> ########>>>>>>>>>
>>
>> and provide commented, minimal, self-contained, reproducible code.

Apologies for an incomplete post. Example code, based on Gabors suggestion is

library(gridExtra)
p1 <- xyplot(demand ~ Time, BOD)
p2 <- xyplot(demand ~ Time, BOD)
p3 <- xyplot(demand ~ Time, BOD)
print(p1, split=c(1,1,2,2), more=TRUE)
print(p2, split=c(2,1,2,2), more=TRUE)
print(p3, split=c(1,2,2,2), more=FALSE)

However, Gabors approach places the mark within the plot itself. What
I'd ideally like is to have the mark be located in the margins, in the
top right corner. (I am not sure of the correct terminology here). An
example of the desired output can be seen at
http://rguha.net/plot-annot.png



-- 
Rajarshi Guha
NIH Chemical Genomics Center



More information about the R-help mailing list