On 6/13/07, Alan S Barnett <[EMAIL PROTECTED]> wrote:
> I'm using xyplot to generate a trellis plot with each panel containing a
> scatterplot and a best fit line.  Is it possible to write the slope of
> the best fit line in each panel?

Sure. The only question is, where (inside the panel) do you want it written?
Here are a couple of possibilities:

## writes the slope at a location that happens to be empty in both
## panels in this example

xyplot(len ~ dose | supp, ToothGrowth,
       panel = function(x, y, ...) {
           panel.xyplot(x, y, ...)
           fm <- lm(y ~ x)
           panel.abline(reg = fm)
           slope <- round(coef(fm)[2], 3)
           panel.text(1.5, 5, lab = slope)
       })


## needs the user to click on a suitable position for each panel

library(grid)

xyplot(len ~ dose | supp, ToothGrowth,
       panel = function(x, y, ...) {
           panel.xyplot(x, y, ...)
           fm <- lm(y ~ x)
           panel.abline(reg = fm)
           slope <- round(coef(fm)[2], 3)
           message("Click on desired location")
           panel.text(grid.locator("native"), lab = slope)
       })

-Deepayan

______________________________________________
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