Hi:
The function ggplot_build() is one way to grab information like this from a plot, but in the future, this will probably be controlled by the gtable package if it is not already. The group mapping was unnecessary so I removed it.
p <- qplot(temperature, DN, color=Image, data=vthcal1MIDAScal1m,
geom=c("point","smooth"), method="lm") +
facet_wrap(~Image,ncol=2)
line_data <- ggplot_build(p)$data[[2]]
line_data <- subset(line_data, PANEL == 1)
p + geom_line(data = line_data, aes(x = x, y = y, color = colour))
Another way to have gone about this would have been to fit linear models to each subset of data first, extracted their intercepts and slopes, and then used geom_abline(). For the reference line, I just plugged in the values of intercept and slope.
lmcoef <- ddply(vthcal1MIDAScal1m, "Image",
function(d) coef(lm(DN ~ temperature, data = d)))
names(lmcoef) <- c("Image", "b0", "b1")
ggplot(data=vthcal1MIDAScal1m, aes(x = temperature, y = DN)) +
geom_point(aes(color = Image)) +
geom_abline(data = lmcoef, aes(intercept = b0, slope = b1, color = Image)) +
geom_abline(intercept = 29468.87, slope = 124.6561, color = "red") +
facet_wrap(~ Image, ncol = 2)
I used ggplot() in this case because you want color to be mapped to points and the first call to geom_abline(), but not the second.
HTH,
Dennis