I have a dataframe with three columns, call it (X,Y,Z). Such that:
- X is numeric variable
- Y is a numeric variable
- Z is a factor variable
I want to plot (using ggplot2) Y againts X and make color groups based on the factor variable Z. This I have managed!
Now I need to plot some regression lines, I know how to plot a regression line for each set of points belonging to the same category (i.e. same factor variable Z). However what I need is to plot TWO regression lines for each category (might seem weird but in the problem I am dealing with it is the way is always done). So, for each category (Z) I should have a regression line computed from the first n elements (belonging to that category) and a second regression line made from the remaining points in the given category, of course both of these lines should have the same color as they interpolate points in a given category (i.e. same color group).
Any help is very much appreciated! Thank you in advance