Hello everyone I have data grouped by subjects and i used the trellis plot to show the curve for each subject. I have another vector "a" which gives me the highest points the curves for each subjects can achieve ( the curve is exponential ). Now i want to draw a horizontal line, whose values are saved in "a", on each plot for each subject. Is there any possibility to do that? Obviously i should use something like panel.abline, the problem is how i can inform R that each value in "a" is a horizontal line for each plot. Thanks a lot for answers. Dassy
Dear Dassy, I'm not entirely sure of the specifics of what you want to achieve, but for similar sounding things I typically make use of the subscripts argument to panel functions. Check out the following simple example. x <- rnorm(500) y <- 0.9*x + sqrt(1-0.9*0.9)*rnorm(500) g <- sample(x=LETTERS[1:3], size=500, replace=TRUE) a <- rnorm(500) tmp <- data.frame(x=x, y=y, a=a, subject=g) # xyplot(y ~ x | subject, data=tmp, panel=function (x,y,subscripts=subscripts,m=a,...) { panel.xyplot(x,y,...) panel.abline(h=max(m[subscripts])) }, key=list(space="top", lines=list(lty=1), text=list ("Maximum"))) Regards, Andrew C. Ward CAPE Centre Department of Chemical Engineering The University of Queensland Brisbane Qld 4072 Australia andreww at cheque.uq.edu.au Quoting "Brunschwig, Hadassa {PDMM~Basel}" <HADASSA.BRUNSCHWIG at Roche.COM>:> Hello everyone > > I have data grouped by subjects and i used the trellis > plot to show the curve for each subject. I have another > vector "a" which gives me the highest points the curves > for each subjects can achieve ( the curve is exponential > ). Now i want to draw a horizontal line, whose values are > saved in "a", on each plot for each subject. Is there any > possibility to do that? Obviously i should use something > like panel.abline, the problem is how i can inform R that > each value in "a" is a horizontal line for each plot. > > Thanks a lot for answers. > > Dassy > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
On Wednesday 13 August 2003 07:43, Brunschwig, Hadassa {PDMM~Basel} wrote:> Hello everyone > > I have data grouped by subjects and i used the trellis plot to show the > curve for each subject. I have another vector "a" which gives me the > highest points the curves for each subjects can achieve ( the curve is > exponential ). Now i want to draw a horizontal line, whose values are saved > in "a", on each plot for each subject. Is there any possibility to do that? > Obviously i should use something like panel.abline, the problem is how i > can inform R that each value in "a" is a horizontal line for each plot.Some more clarification on your data structure would have helped. Is your variable "a" a part of the data frame (with the same value repeated for all rows corresponding to each subject), or is it a separate, shorter vector, with length equal to the number of subjects ? If the former, then you should use subscripts, as others have already suggested, perhaps as: xyplot(y ~ x | subject, data = foo, panel = function(x, y, subscripts, ...) { panel.xyplot(x, y, ...) panel.abline(h=foo$a[subscripts][1], ...) }) In the second case, you could do something similar to determine (inside the panel function) which element of "a" you need to use (assuming the grouping variable "subject" is a factor): panel.abline(h = a[as.numeric(foo$subject)[subscripts][1]], ...) (assuming that the grouping variable "subject" is a factor) Alternatively, you could probably also get away with xyplot(y ~ x | subject, data = foo, panel = function(x, y, panel.number, ...) { panel.xyplot(x, y, ...) panel.abline(h=a[panel.number], ...) }) Deepayan