Subject: xyplot: logarithmic y-axis

From: RMan54 <[email-masked]>
Date: Fri, 15 Dec 2006 14:12:22 -0800 (PST)

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.

______________________________________________
[email-masked] 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.

---

From: "Deepayan Sarkar" <[email-masked]>
Date: Fri, 15 Dec 2006 14:26:47 -0800

> to the panel function and then to the panel.curve function.

It probably should, but doesn't.

-Deepayan

---

From: RMan54 <[email-masked]>
Date: Fri, 15 Dec 2006 14:41:49 -0800 (PST)

Please take no offence since none was intended. What I meant is that it
should be simple for me to know how to do this but it isn't because of my
inexperience. I  think that the lattice package is great.

However, how can I pass on my own varaibles through xyplot?

Thanks, -Rene

Deepayan Sarkar wrote:
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html

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

---

From: "Deepayan Sarkar" <[email-masked]>
Date: Fri, 15 Dec 2006 14:57:07 -0800

> inexperience. I  think that the lattice package is great.

I didn't mean to suggest that I was offended. I only agreed with you
that it would be nice if there were a way of knowing inside the panel
function whether a log scale is being used, and informing you that
there isn't.

> However, how can I pass on my own varaibles through xyplot?

Any arguments not recognized by xyplot will be passed to the panel function.

-Deepayan

---

From: RMan54 <[email-masked]>
Date: Fri, 15 Dec 2006 15:16:38 -0800 (PST)

I added logY as the last argument to xyplot and in my curve function. I got
the following error message:

Error in myCurve(x) : argument "log" is missing, with no default

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

logY=T
xyplot(Conc ~ Time | Subj,
       groups=Dose,
       data = mydata,
       scales=list(x=list(at=seq(0,96,24)), 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, ..., log=logY)
           },
       logY
       )

Deepayan Sarkar wrote:
>> >> I think that the value of logY should go into xyplot that should pass
>> it
>> >> on

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

---

From: "Deepayan Sarkar" <[email-masked]>
Date: Fri, 15 Dec 2006 15:43:57 -0800

>            panel.curve(myCurve, from=0, to=96, n=300, ..., log=logY)

You need to learn more about (1) R functions and (2) R's scoping
rules. Your last argument (logY) is not doing what you think it's
doing (which doesn't really matter because of the scoping rules).

Your error is caused because in

the 'log' argument is not being passed to myCurve (nor is it supposed
to). However, you should be able to replace it by

panel.curve(myCurve(x, log = logY), from=0, to=96, n=300, ...)

-Deepayan