[R] panel.text question

Felix Andrews felix at nfrac.org
Sun Sep 27 13:29:32 CEST 2009


Use packet.number() to identify which data subset you are dealing with
(inside the panel function):

xyplot(y~x|a,
   panel=function(...){
       panel.loess(...)
       panel.text(0,2,label=c('best','better','bad','worst')[packet.number()])
   })

There is also panel.number() which is similar but refers to the panel
position rather than data set. The difference shows up if you
re-arrange the panels from the default ordering.


2009/9/27 Osman Al-Radi <osman.al.radi at gmail.com>:
> Hello,
>
> Thanks for your suggestion. It works in my simplified example. However, it
> didn't work in my real code. It is probably because I neglected to include
> the group argument in the example. I apologize for that.
>
> Below is the real code, if you need the actual data I can include it too.
>
> # this works well
> xyplot(PaCO2~time|group, group=animal,layout=c(3,1,1),aspect=1,
>    panel=function(...){
>        panel.loess(...)
>        panel.superpose(...)}
>    ,data=pig,subset=time>5 & time<181,
>    xlab='Time (minutes)',
>    ylab='PaCO2 (mmHg)')
>
>
> # this gives the following error "Error in using packet 1 data, X argument
> missing with no #default" in each of the plot panel
>
> xyplot(PaCO2~time|group, group=animal,layout=c(3,1,1),aspect=1,
>    panel=function(x,y,subscripts,...){
>        panel.loess(...)
>        panel.superpose(...)
>        panel.text(100,110,label=c(' ','p=0.007','p=0.006')[tail(subscripts,
> 1)])}
>    ,data=pig, subset=time>5 & time<181,
>    xlab='Time (minutes)',
>    ylab='PaCO2 (mmHg)')
>
>
>  Thanks tremendously for your help. I don't know why its soo hard just to
> add some text!
>
> Osman
> Osman O. Al-Radi, MD, MSc, FRCSC
> Staff Cardiovascular Surgeon
> Co-medical director, Tissue Bank
> The Hospital for Sick Children
> University of Toronto, Canada
>
>
> On Thu, Sep 24, 2009 at 2:18 PM, Henrique Dallazuanna <wwwhsd at gmail.com>wrote:
>
>> Try this:
>>
>> xyplot(y ~ x | a,
>>   panel=function(x, y, subscripts, ...){
>>       panel.loess(x, y)
>>       panel.text(0, 2,
>> label=c('best','better','bad','worst')[tail(subscripts, 1)/100])
>>   })
>>
>> On Thu, Sep 24, 2009 at 2:45 PM, Osman Al-Radi <osman.al.radi at gmail.com>
>> wrote:
>> > Dear R-help,
>> >
>> > I would like to add text to each of four panels in a plot generated by
>> > xyplot in lattice library. A sample code is given below, the plot
>> generated
>> > has the first label repeated in all panels!
>> >
>> > How can I get the labels to be different in each panel?
>> >
>> > library(lattice)
>> > x <- rnorm(400)
>> > y <- rnorm(400)
>> > a <- gl(4, 100)
>> >
>> > xyplot(y~x|a,
>> >    panel=function(...){
>> >        panel.loess(...)
>> >        panel.text(0,2,label=c('best','better','bad','worst'))})
>> >
>> > Thanks
>> >
>> > Osman
>> >
>> >
>> >
>> > Osman O. Al-Radi, MD, MSc, FRCSC
>> > Staff Cardiovascular Surgeon
>> > Co-medical director, Tissue Bank
>> > The Hospital for Sick Children
>> > University of Toronto, Canada
>> >
>> >        [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>>
>>
>>
>> --
>> Henrique Dallazuanna
>> Curitiba-Paraná-Brasil
>> 25° 25' 40" S 49° 16' 22" O
>>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 1670
E: felix.andrews at anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/




More information about the R-help mailing list