[R] Passing arguments to panels in trellis plots
Deepayan Sarkar
deepayan.sarkar at gmail.com
Thu Dec 14 02:17:14 CET 2006
On 12/13/06, Marco Chiarandini <marco at imada.sdu.dk> wrote:
> Dear Deepayan,
>
>
> > Since you haven't bothered to follow the posting guide at all, it took
> > me a while to figure out that you live in that alternate R universe
> > created by Prof Harrell. Can't help you there, but in the standard
> > universe, things seem fairly simple:
>
>
> I am sorry for not having been clear. I hope this time I get closer to
> the correct post practice.
>
> Here is what I am trying to do:
>
> D <- expand.grid(rep=c(1:10),b=c("M","N"),a=c("10","20"),alg=c("A","B"))
> D1 <- data.frame(D[,c(2,3,4)],time=runif(80,1,100))
> D2 <- data.frame(D1,event=rbinom(80,1,0.9))
>
> library(survival)
> library(lattice)
> library(Hmisc)
> Ecdf(~time | a*b, groups=alg,data=D2,
> subscripts=TRUE,
> panel=function(x,groups,subscripts)
> {
> t <-
> survfit(Surv(time[subscripts],event[subscripts])~groups[subscripts],
> data=D2,type="kaplan-meier",
> conf.type="plain",conf.int=.95, se.fit=T)
> panel.xyplot(t[2]$time,1-t[2]$surv,type="s",lty=2)
> panel.xyplot(t[1]$time,1-t[1]$surv,type="s",lty=1)
> }
> )
>
>
> Although not very elegant this does the job. Nevertheless, when I try to
> add:
>
> scales = list(log=TRUE)
>
> in the Ecdf fucntion above I incurr in problems because the
> transformation of data occurs before applying the function Surv.
Yes, that's a feature of lattice.
> Hence my question, is there a way to plot survfit in trellis plots with
> different strata (the alg factor above) in the same plot and conditional
> to combination of other factors (the a and b factors above)?
Not if you insist on using 'scales = list(log = TRUE)' to specify log
scales. Use a different argument that gets passed to the panel
function, and then use it in the panel function. I suspect you are
using Ecdf simply to get a probability scale on the y-axis; the proper
way to specify data-based limits is to write a prepanel function, as
explained in ?xyplot.
-Deepayan
More information about the R-help
mailing list