Thanks for the reply. Trunc would only work when the truncated y values
result in the desired y coordinates for the grid lines as in this simple
data set. Since my real dataset contains many more points, it does not give
a general solution.

Rene  

-----Original Message-----
From: Bernd Weiss [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 20, 2007 9:44 PM
To: Rene Braeckman; r-help@stat.math.ethz.ch
Subject: Re: [R] Different gridlines per panel in xyplot

Am 20 Feb 2007 um 20:52 hat Rene Braeckman geschrieben:

From:                   "Rene Braeckman" <[EMAIL PROTECTED]>
To:                     <r-help@stat.math.ethz.ch>
Date sent:              Tue, 20 Feb 2007 20:52:29 -0800
Subject:                [R] Different gridlines per panel in xyplot

> In the example R script below, horizontal gray gridlines are drawn at 
> y coordinates where the points are drawn with the code:
> 
> panel.abline(h=y, v=xScale, col.line="gray")
> 
> How do I change this so that the horizontal gray gridlines are drawn 
> at y coordinates where the y labels are drawn? The challenge is that 
> each panel has different y-ranges (in my real example the y-ranges and 
> y-intervals are even more different). For example, I wish I could use 
> the yScale list as the h parameter in abline, but it does not work 
> with a list.
> 
> Thanks for any help.
> Rene
> 
> library(lattice)
> Subj <- rep(1:4,each=3)
> Time <- rep(1:3,4) + 0.1
> Conc <- (1:12) + 0.1
> df <- data.frame(Subj,Time,Conc)
> xScale <- 1:3
> yScale <- list(1:3,4:6,7:9,10:12)
> xyplot(Conc ~ Time | Subj,
>        data = df,
>        layout = c(2,2),
>        type="b",
>        scales=list(
>           x=list(at=xScale),
>           y=list(at=yScale,relation="free")
>        ),
>        panel = function(x,y,...) {
>            panel.abline(h=y, v=xScale, col.line="gray")
>            panel.xyplot(x,y,...)
>       }
> )
> 

Dear Rene,

I am not quite sure whether this is the most elegant/general solution, but
one option might be to use trunc(), see the full code below.

panel.abline(h=trunc(y), v=xScale, col.line="gray")


library(lattice)
Subj <- rep(1:4,each=3)
Time <- rep(1:3,4) + 0.1
Conc <- (1:12) + 0.1
df <- data.frame(Subj,Time,Conc)
xScale <- 1:3
yScale <- list(1:3,4:6,7:9,10:12)
xyplot(Conc ~ Time | Subj,
       data = df,
       layout = c(2,2),
       type="b",
       scales=list(
          x=list(at=xScale),
          y=list(at=yScale,relation="free")
       ),
       panel = function(x,y,...) {
                ## use trunc(y)
           panel.abline(h=trunc(y), v=xScale, col.line="gray")
           panel.xyplot(x,y,...)
      }
)


HTH,

Bernd

______________________________________________
R-help@stat.math.ethz.ch 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.

Reply via email to