On 12-06-24 04:43 PM, Manuel Spínola wrote:I can't see how to do it without running lm() outside of the ggplot
> Dear list members,
>
> Is it posible to draw lines form the observation points to a fitted
> regression line?
>
> c <- ggplot(mtcars, aes(qsec, wt))
> c + stat_smooth(method = "lm") + geom_point()
>
> Best,
>
> Manuel
>
call, but it's pretty easy:
library(ggplot2)
c <- ggplot(mtcars, aes(qsec, wt))lm1 <- lm(wt~qsec,data=mtcars)
c1 <- c + stat_smooth(method = "lm") + geom_point() +
geom_segment(data=fortify(lm1),
aes(yend=.fitted,xend=qsec))
> --
> *Manuel Spínola, Ph.D.*
> Instituto Internacional en Conservación y Manejo de Vida Silvestre
> Universidad Nacional
> Apartado 1350-3000
> Heredia
> COSTA RICA
> mspi...@una.ac.cr <mailto:mspi...@una.ac.cr>
> mspin...@gmail.com <mailto:mspin...@gmail.com>
> Teléfono: (506) 2277-3598
> Fax: (506) 2237-7036
> Personal website: Lobito de río
> <https://sites.google.com/site/lobitoderio/>
> Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>
>
> --
> You received this message because you are subscribed to the ggplot2
> mailing list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2