Here's an example:
eg <- data.frame(x = c(1:50, 50:1),
y = c(1:50, 1:50) + rnorm(100),
g = rep(c("a","b"), each=50))
qplot(x, y, data = eg) +
facet_wrap(~ g) +
geom_smooth()
I'd like to be able to plot the overall smooth on both facets as well as having the facet-specific smooths.
Edit: here's one way.
my.smooth <- gam(y ~ s(x), data = eg)
my.data <- data.frame(x = 1:50)
my.data$y <- predict(my.smooth, newdata = my.data)
qplot(x, y, data = eg) +
facet_wrap(~ g) +
geom_smooth() +
geom_smooth(data = my.data)
Thanks for any help!
Andrew