Skip to content

How do I perform conditional annotation of lattice

1 message · Karl Ropkins

#
Not sure if this adds much to Ken Knoblauch previous suggestion. But:



Subject<-c(1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4)
Day<-c(1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6)
Activity<-c(2,3,4,3,7,4,5,8,2,8,4,6,2,5,3,8,9,5,6,3,4,5,6,7)
EventA<-c("Yes",NA,"Yes",NA,NA,NA,"Yes",NA,NA,NA,NA,NA,
          "Yes",NA,NA,NA,NA,NA,NA,NA,"Yes",NA,NA,NA)

require(loa)

panel.temp = function(x=x, y=y, z=z, ...){
                         panel.xyplot(x, y, z =1, ...)
                         panel.abline(v=x[!is.na(z)], col="red")
}
loaPlot(EventA ~ Day*Activity|Subject, panel=panel.temp, type="b")



The loa package is still a little messy, not yet on CRAN and the help is only half written but you are welcome to have a play:

https://sites.google.com/site/karlropkins/rpackages/loa



The basic plot is z ~ x * y, where z is information to be displayed at (x,y) and the package includes a very inelegant alternative to subscripting.



Regards,



Karl Ropkins

ITS Leeds

------------------------------





Date: Tue, 7 Jan 2014 15:50:39 +0000
From: Ken Knoblauch <ken.knoblauch at inserm.fr<mailto:ken.knoblauch at inserm.fr>>
To: <r-<mailto:r-help at stat.math.ethz.ch>help at stat.math.ethz.ch>
Subject: Re: [R] How do I perform conditional annotation of lattice
        panel   plots?
Message-ID: <loom.20140107T164813-513 at post.gmane.org<mailto:loom.20140107T164813-513 at post.gmane.org>>
Content-Type: text/plain; charset="utf-8"

Chen, George <George.Chen <at> roswellpark.org> writes:
been asked before. I am trying to plot activity
Code for sample data below.
where on these activity curves Event A occurs.
This is to explore the
cutting through the curve at the day Event A occurred, but
-----snip -------------
and/or confidential information.  If you are not the
responsible for the delivery of this message to the
that any disclosure, copying, distribution, or use of
received this message in error, please notify the sender
message from your computer. Thank you.
You used Time in your formula but Day in
your data so I changed the formula to Day
assuming that's what you meant

Perhaps, not the most elegant solution, but
how about something like this

library(lattice)
Subject<-c(1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4)
Day<-c(1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6)
Activity<-c(2,3,4,3,7,4,5,8,2,8,4,6,2,5,3,8,9,5,6,3,4,5,6,7)
EventA<-c("Yes",NA,"Yes",NA,NA,NA,"Yes",NA,NA,NA,NA,NA,
          "Yes",NA,NA,NA,NA,NA,NA,NA,"Yes",NA,NA,NA)
Data<-data.frame(cbind(Subject,Day,Activity,EventA))

xyplot(Activity~ Day | Subject)
xyplot(Activity ~ Day | Subject, data = Data,
        subscripts = TRUE,
        panel = function(x, y, subscripts, ...){
                panel.xyplot(x, y)
                wh <- Data[subscripts, ]
                panel.abline(v = wh$Day[!is.na(wh$EventA)])
        })

--
Kenneth Knoblauch
Inserm U846
Stem-cell and Brain Research Institute
Department of Integrative Neurosciences
18 avenue du Doyen L?pine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html