[R] Multiple ablines

Dieter Menne dieter.menne at menne-biomed.de
Sun Apr 9 11:31:55 CEST 2006

G. Alex Janevski <galexski <at> umich.edu> writes:

> points(y~x, pch="*", col="black")
> lm(y~x)
> fm=lm(y~x)
> abline(fm, col="red")
> This works. The problem arises in that I would like to run my simulation 
> multiple times, to plot the data points together on the same plot, and 
> more importantly the regression lines of the simulated data. Therefore, 
> I have placed the code within the loop of the simulation. This works 
> fine for points(), I can watch the additional points being added to the 
> plot as the simulations run. However, when I include abline() it gives 
> this error: "Error in abline(a, b, h, v, untf, col, lty, lwd, ...) :
>         'a' and 'b' must be finite"
> I can take the code as written and place it outside of the loop and it 
> works fine, plotting the points and regression line for the data of the 
> last run of the simulation. 

Just a guess: try to call plot(...) in each repetition of the loop once; points 
and lines require an existing plot, where scaling etc. is already defined.


More information about the R-help mailing list