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
Plotting multiple ablines
5 messages · Rolf Turner, Uwe Ligges, r at quantide.com +1 more
On 2/04/2009, at 7:04 AM, Thomas Levine wrote:
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
The help for abline explicitly states that a and b must be ``single
values'';
so no vectorization appears to be possible, as abline is currently
written.
Hence you are stuck with a for-loop.
There appears to be nothing wrong with the for-loop that you've written,
at first blush at least.
There won't be NAs in ``converge'' since you've very cleverly used
na.omit.
So ``missing data'' are NOT the problem.
The problem is then (probably) that some of your data are yielding
infinite
values of tan().
***Look*** at the values in converge. ***Look*** at the values of a
and b
produced in your loop and see where you're getting infinite values.
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
Rolf Turner wrote:
On 2/04/2009, at 7:04 AM, Thomas Levine wrote:
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
The help for abline explicitly states that a and b must be ``single values''; so no vectorization appears to be possible, as abline is currently written. Hence you are stuck with a for-loop. There appears to be nothing wrong with the for-loop that you've written, at first blush at least.
Or use mapply(). Untested:
mapply(abline, tan(converge$kT * pi / 180),
converge$kY - tan(-converge$kT * converge$kX * pi / 180))
Uwe Ligges
There won't be NAs in ``converge'' since you've very cleverly used na.omit.
So ``missing data'' are NOT the problem.
The problem is then (probably) that some of your data are yielding infinite
values of tan().
***Look*** at the values in converge. ***Look*** at the values of a and b
produced in your loop and see where you're getting infinite values.
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
______________________________________________ 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.
May be:
plot(c(-1, 1) , c(-1, 1), type = "n")
n = 4
a = rep(0, n)
b = 1:n/n
fun = function(i, a, b, col = 1 , ...) {
abline(a[i], b[i], col = col[i], ...)
}
lapply(1:n, fun, a=a, b=b, col = 1:n)
Andrea
Thomas Levine wrote:
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
______________________________________________ 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.
1 day later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090403/59b5a682/attachment-0001.pl>