title: plotting regression line in with lattice
body: <p>I'm having a bit of a trouble here, please help me.
  I have this data</p>
  
  <pre><code>set.seed(4)
  mydata &lt;- data.frame(var = rnorm(100),
                       temp = rnorm(100),
                       subj = as.factor(rep(c(1:10),5)),
                       trt = rep(c("A","B"), 50))
  </code></pre>
  
  <p>and this model that fits them</p>
  
  <pre><code>lm  &lt;- lm(var ~ temp * subj, data = mydata)
  </code></pre>
  
  <p>I want to plot the results with <strong>lattice</strong> and fit the regression line, predicted with my model, through them. To do so, I'm using this approach, outlined  "Lattice Tricks for the power useR" by D. Sarkar</p>
  
  <pre><code>temp_rng &lt;- range(mydata$temp, finite = TRUE)
  
  grid &lt;- expand.grid(temp = do.breaks(temp_rng, 30),
                      subj = unique(mydata$subj),
                      trt = unique(mydata$trt))
  
  model &lt;- cbind(grid, var = predict(lm, newdata = grid))
  
  orig &lt;- mydata[c("var","temp","subj","trt")]
  
  combined &lt;- make.groups(original = orig, model = model)
  
  
  xyplot(var ~ temp | subj, 
         data = combined,
         groups = which,
         type = c("p", "l"),
         distribute.type = TRUE
         )
  </code></pre>
  
  <p>So far every thing is fine, but I also want to assign a fill color to the data points for the two treatments <code>trt=1</code> and <code>trt=2</code>. </p>
  
  <p>So I have written this piece of code, that works fine, but when it comes to plot the regression line, it seems that type is not recognized by the panel function... </p>
  
  <pre><code>my.fill &lt;- c("black", "grey")
  
  plot &lt;- with(combined,
          xyplot(var ~ temp | subj,
                data = combined,
                group = combined$which,
                type = c("p", "l"),
                distribute.type = TRUE,
                panel = function(x, y, ..., subscripts){
                       fill &lt;- my.fill[combined$trt[subscripts]] 
                       panel.xyplot(x, y, pch = 21, fill = my.fill, col = "black")
                       },
               key = list(space = "right",
                       text = list(c("trt1", "trt2"), cex = 0.8),
                       points = list(pch = c(21), fill = c("black", "grey")),
                       rep = FALSE)
                       )
        )
  plot
  </code></pre>
  
  <p>I've also tried to move type and distribute type within <code>panel.xyplot</code>, as well as subsetting the data in it <code>panel.xyplot</code> like this</p>
  
  <pre><code>plot &lt;- with(combined,
          xyplot(var ~ temp | subj,
                data = combined,
                panel = function(x, y, ..., subscripts){
                       fill &lt;- my.fill[combined$trt[subscripts]] 
                       panel.xyplot(x[combined$which=="original"], y[combined$which=="original"], pch = 21, fill = my.fill, col = "black")
                       panel.xyplot(x[combined$which=="model"], y[combined$which=="model"], type = "l", col = "black")
                       },
               key = list(space = "right",
                       text = list(c("trt1", "trt2"), cex = 0.8),
                       points = list(pch = c(21), fill = c("black", "grey")),
                       rep = FALSE)
                       )
        )
  plot
  </code></pre>
  
  <p>but no success with that either. </p>
  
  <p>Can anyone help me to get the predicted values plotted as a line instead of being points? </p>