I'm searching how to (visually) explain simple linear correlation to first year students.
The classical way to visualize would be to give an Y~X scatter plot with a straight regression line.
Recently, I came by the idea of extending this type of graphics by adding to the plot 3 more images, leaving me with: the scatter plot of y~1, then of y~x, resid(y~x)~x and lastly of residuals(y~x)~1 (centered to the mean)
Here is an example of such a visualization:
And the R code to produce it:
set.seed(345) x <- runif(50) * 10 y <- x +rnorm(50) layout(matrix(c(1,2,2,2,2,3 ,3,3,3,4), 1,10)) plot(y~rep(1, length(y)), axes = F, xlab = "", ylim = range(y)) points(1,mean(y), col = 2, pch = 19, cex = 2) plot(y~x, ylab = "", ) abline(lm(y~x), col = 2, lwd = 2) plot(c(residuals(lm(y~x)) + mean(y))~x, ylab = "", ylim = range(y)) abline(h =mean(y), col = 2, lwd = 2) plot(c(residuals(lm(y~x)) + mean(y))~rep(1, length(y)), axes = F, xlab = "", ylab = "", ylim = range(y)) points(1,mean(y), col = 2, pch = 19, cex = 2)
Which leads me to my question: I would appreciate any suggestions on how this graph can be enhanced (either with text, marks, or any other type of relevant visualizations). Adding relevant R code will also be nice.
One direction is to add some information of the R^2 (either by text, or by somehow adding lines presenting the magnitude of the variance before and after the introduction of x) Another option is to highlight one point and showing how it is "better explained" thanks to the regression line. Any input will be appreciated.