Skip to content
Prev 304410 / 398503 Next

Lattice graphics adding abline line (1:1 line) ???

On 2012-08-27 15:49, iwaite wrote:
I don't know what a "1:1 line" is, but your (nonreproducible)
code suggests that you want a regression line (or lines?).
As for auto.key, it may be better to use the "key" argument.

Here are a couple of suggestions (using the iris data)
that may help you:

1. If you just want a single regression line for all groups
combined:

   library(lattice)
   xyplot(Sepal.Length ~ Sepal.Width, data = iris,
     groups = Species,
     pch = 15:17, col = 2:4,
     panel = function(x,y,...){
       panel.xyplot(x,y,...)
       panel.lmline(x,y)},
     key = list(corner = c(1,0),
             text = list(lab = levels(iris[["Species"]])),
             points = list(pch = 15:17, col = 2:4)))

2. If you want separate regression lines for each group:

   xyplot(Sepal.Length ~ Sepal.Width, data=iris,
     groups = Species,
     pch = 15:17, col = 2:4,
     panel = "panel.superpose",
     panel.groups = function(x,y,...){
       panel.xyplot(x,y,...)
       panel.lmline(x,y,...)
     },
     key = list(corner = c(1,0),
             text = list(lab = levels(iris[["Species"]])),
             points = list(pch = 15:17, col = 2:4)))

If you use panel.abline for regression lines, be sure to
specify the regression formula with the "reg=" argument.

Peter Ehlers