[R] abline by groups

Uwe Ligges ligges at statistik.tu-dortmund.de
Fri Jan 20 20:30:22 CET 2012



On 20.01.2012 16:38, Sam Chand wrote:
> Hello,
> I have 2 variables - x and y, that belong to separate groups.
> I want to plot all the x and y together, but show separate abline  for each
> group. It can be done in ggplot2, but is there a simpler way to draw
> ablines by group?
> e.g.,
>
> mydata<- data.frame(x = 1:20+rnorm(20, -3, 1), y = seq(1,20,by=1), group =
> rep(letters[1:5],20))
> plot(x,y,col=mydata$group)  # need to get separate ablines for each
> color-code


1. The code does not run as is.

2. abline for more than two points is nonsense for your data, since the 
groups are not at all on one line.

3. So you may want separate regressions? Or a whole model of the data 
with different intercepts and same slope? Or in one model with different 
intercepts and different slopes?

Hence we cannot help and for now I assume this is a homework problem and 
you have not even repeated the question properly.

Uwe Ligges



>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list