[R] adding to Trellis plot
Damon Wischik
djw1005 at cam.ac.uk
Wed Aug 13 22:38:26 CEST 2003
> I have grouped data and i used a Trellis plot to show the curve of a
> fitted model for each group. Additionally i have a vector whose values
> are the highest points the curve can reach (the curve rises
> exponetially). Each value of the vector is the corresponding highest
> point for each group/plot. Now i want to show this highest point by
> adding to each plot a horizontal line.
Do you mean group or panel? You say "adding to each plot", so I guess you
mean panel.
I would use the subscripts argument to xyplot. If subscripts=TRUE in the
arguments to xyplot (and in some other cases), the panel function is
passed an argument called subscripts, a vector of integer indices
indicating which points are about to be plotted. This lets you work out
which rows of your data frame are about to be plotted, which should let
you print your extra graphical elements.
mydf <- data.frame(x=rnorm(20),y=rnorm(20),t=rbinom(20,1,.5))
xyplot(y~x|t, data=mydf, subscripts=TRUE,
panel=function(x,y,subscripts,...) {
panel.xyplot(x,y)
print(subscripts)
currentpanel <- unique(mydf$t[subscripts])
print(currentpanel)
panel.abline(something to do with currentpanel)
})
Damon.
More information about the R-help
mailing list