[R] adding text to the top corner of a lattice plot
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Dec 17 13:08:09 CET 2010
On Fri, Dec 17, 2010 at 7:04 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> On Fri, Dec 17, 2010 at 6:57 AM, Gabor Grothendieck
> <ggrothendieck at gmail.com> wrote:
>> On Fri, Dec 17, 2010 at 12:07 AM, Rajarshi Guha <rajarshi.guha at gmail.com> wrote:
>>> 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
>>
One more small improvement:
library(gridExtra)
pgfun <- function(mark) function(n) grid.text(label = mark,
x = unit(0.1, "npc"), y = unit(0.9, "npc"))
fo <- demand ~ Time
grid.arrange(nrow = 2,
xyplot(fo, BOD, page = pgfun("A")),
xyplot(fo, BOD, page = pgfun("B")),
xyplot(fo, BOD, page = pgfun("C"))
)
--
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