[R] Modifications to an abline

Douglas Bates bates at stat.wisc.edu
Sun Nov 28 18:57:17 CET 2004

Doran, Harold wrote:
> Dear List:
> I am working to generate graphs for individual students that will be
> created through a series of loops in Sweave. Before doing so, I am
> still trying to design the graph. The code for creating the barplot
> is below with some sample datapoints just made up for now.
> Ultimately, this chart will take data from an lme object using
> longitudinal student data. So, the dots represent the observed
> student scores at each occasion and the abline will be added using
> the data from coef(), which gives the intercept and slope for each
> individual student.
> Now, the abline currently extends the entire graph, which I do not
> want exactly. Assume I only have data at grades 1,2, and 3 for this
> individual. I would want the abline to extend only as far as the
> observed data using a lty=1.
> However, I want to show an extrapolated line from the current score
> to the end of the graph. I want for this line to be dashed, something
> like lty=2.
> So, while the abline should extend the length of the chart, I want
> for it to change in style at a specified point. Can this be done?
> Last, I'm not sure I want the abline to extend the entire region of
> the chart, but maybe say to the middle of the barplot.
> I would appreciate any thoughts on this. Any thoughts on code to
> improve the chart is also appreciated.

One approach is to use abline to put the dashed line on the plot then 
use segments to add the line covering the observed range with lty = 1.
You will need to calculate the end points of the solid line but those 
are just the values of the fitted line at the minimum and maximum 
observed grade levels.

More information about the R-help mailing list