I'm creating a facetted plot to view predicted vs. actual values side by side with a plot of predicted value vs. residuals. I'll be using shiny to help explore the results of modeling efforts using different training parameters. I train the model with 85% of the data, test on the remaining 15%, and repeat this 5 times, collecting actual/predicted values each time. After calculating the residuals, my data.frame looks like this:
head(results)
act pred resid
2 52.81000 52.86750 -0.05750133
3 44.46000 42.76825 1.69175252
4 54.58667 49.00482 5.58184181
5 36.23333 35.52386 0.70947731
6 53.22667 48.79429 4.43237981
7 41.72333 41.57504 0.14829173
What I want:
- Side by side plot of
predvs.actandpredvs.resid - The x/y range/limits for
predvs.actto be the same, ideally frommin(min(results$act), min(results$pred))tomax(max(results$act), max(results$pred)) - The x/y range/limits for
predvs.residnot to be affected by what I do to the actual vs. predicted plot. Plotting forxover only the predicted values andyover only the residual range is fine.
In order to view both plots side by side, I melt the data:
library(reshape2)
plot <- melt(results, id.vars = "pred")
Now plot:
library(ggplot2)
p <- ggplot(plot, aes(x = pred, y = value)) + geom_point(size = 2.5) + theme_bw()
p <- p + facet_wrap(~variable, scales = "free")
print(p)
That's pretty close to what I want:

What I'd like is for the x and y ranges for actual vs. predicted to be the same, but I'm not sure how to specify that, and I don't