[R] xyplot: logarithmic y-axis

RMan54 RMan54 at cox.net
Fri Dec 15 23:12:22 CET 2006


This should be simple but I am struggling. I like to easily switch in xyplot
between a linear or logarithmic y-axis by setting a logical flag logY to
False or True. This switch changes the scales argument of xyplot. I found
out that the original two-dimentional data (Conc vs Time in my case) are
converted to log10(Conc) if log=TRUE in scales, but it appears that
functions like panel.curve need to provide the y values in log10 form (if
there is an automatic method, I would like to know). I therefore like to
pass on the value logY to my custom panel.curve function. How do I do that?
I think that the value of logY should go into xyplot that should pass it on
to the panel function and then to the panel.curve function.

Thanks, -Rene

logY=TRUE

# Custom panel.curve function
myCurve <-function(x, log) {
    f <- ...   #  calculate curve here
    if (log==TRUE) f <- log10(f)
    return(f)
}

xyplot(Conc ~ Time | Subj,
       groups=Dose,
       data = mydata,
       as.table=TRUE,
       scales=list(y=list(log=logY)),
       panel = function(...) {
           panel.abline(h=c(0, 50, 100, 150, 200, 250) ,
                      v=c(0,24,48,72,96), col.line="gray")
           panel.xyplot(...)
           panel.curve(myCurve, from=0, to=96, n=300))
           }
       )

-- 
View this message in context: http://www.nabble.com/xyplot%3A-logarithmic-y-axis-tf2829755.html#a7900202
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list