Plotting manual fitted model predictions using ggplot
Posted on December 26, 2012
ggplot provides convenient smoothing functions for fitting models to data with
the built in geom_smooth and stat_smooth methods.
When you are faceting data, either spatially or by color/linetype/shape doing the subsetting and model fitting manually can be somewhat daunting.
However once you understand the process, and are familiar with the plyr library of
functions it is actually very straightforward.
The only change for two facets is how you break up the models
If you want to perform predictions across the full range of data you can use
expand.grid with the full dataset rather than just the subset, this is
analogous to the fullrange option in stat_smooth
So you can see that plotting manual predictions is actually very
straightforward, and this can be a powerful technique in exploratory data