[R] Plotting multiple ablines

Thomas Levine thomas.levine at gmail.com
Wed Apr 1 20:04:50 CEST 2009


I really want to do this:

abline(
a=tan(-kT*pi/180),
b=kY-tan(-kT*pi/180)*kX
)

where kX,kY and kT are vectors of equal length. But I can't do that
with abline unless I use a loop, and I haven't figured out the least
unelegant way of writing the loop yet. So is there a way to do this
without a loop?

Or if I am to resort to the loop, what's the best way of doing it
considering that I have some missing data? Here's the mess that I
wrote.

converge <- na.omit(data.frame(kX,kY,kT))
for (z in (length(converge$kT)))
{abline(
a=tan(converge$kT[z]*pi/180),
b=converge$kY[z]-tan(-converge$kT[z]*converge$kX[z]*pi/180)
)}

I think the missing data are causing the problem; this happens when I run:

Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
  'a' and 'b' must be finite




More information about the R-help mailing list