0

Suppose that I have a scatter plot of points (x_i,y_i) and I want to plot the fitted regression line and then drop a line from each point to the line (in a different color) to show the residuals. How can this be done in R, preferably with ggplot?

passerby51
  • 835
  • 2
  • 9
  • 23
  • see `?fortify`, `?geom_segment` ... have you made any attempts for yourself yet? – Ben Bolker Apr 11 '15 at 03:43
  • It would be helpful to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data and the code you're using to fit the model. – MrFlick Apr 11 '15 at 03:43
  • @BenBolker, Thanks, I haven't since ggplot2 does not seem to allow multiple plots on the same axis and I find the syntax in general very convoluted. – passerby51 Apr 11 '15 at 03:51
  • hmm. Why then do you prefer ggplot2? – Ben Bolker Apr 11 '15 at 03:59
  • @BenBolker, Great! That seems to be what I was looking for. Re why I prefer `ggplot2`, I haven't yet made up my mind. Its plots look nicer out of the box, though it seems one has to go to great lengths to produce nonstandard plots. I am asking since I simply want to see how it is done with ggplot2, and whether it is worth investing time learning about it. – passerby51 Apr 11 '15 at 04:14

0 Answers0