[R] intercept point coordinates
Peter Ehlers
ehlers at ucalgary.ca
Mon Jan 17 15:39:30 CET 2011
On 2011-01-17 04:14, Tonja Krueger wrote:
> Hi List,
> Can someone help me to calculate the coordinates of the red and green points? In this
> example I found their approximate location by trying, but as I have to analyse
> many similar curves, I’d rather calculate the exact location.
>
> data<-
> c(0.008248005, 0.061242387, 0.099095516, 0.189943027, 0.227796157, 0.258078661,
> 0.280790538, 0.303502416, 0.386779301, 0.454914934, 0.545762445, 0.591186201,
> 0.682033712, 0.757739971, 0.825875604, 0.848587482, 0.803163726, 0.833446230,
> 0.878869985, 0.871299359, 0.878869985, 0.947005619, 1.000000000, 0.992429374,
> 0.954576245, 0.894011237, 0.765310597, 0.621468704, 0.492768064, 0.333784920,
> 0.258078661, 0.174801775, 0.099095516, 0.008248005)
>
> plot(data, type="l")
> abline(h=0.9)
>
> points(21.35,.9, pch=20, col="red")
> points(26,.9, pch=20, col="green")
>
>
> Thank you,
> Tonja
You can do this with graphics, using the locator() function:
plot(data, type="l")
abline(h=0.9)
v <- locator(2)
Now click on the intersection points and then extract v$x.
It's best to blow up the relevant region of the plot
(perhaps for each point separately) with appropriate
xlim/ylim settings and to maximize your plot window.
Alternatively, you can identify that the points lie
in data[21:22] and in data[25:26]. Then use the
approx() function:
approx(data[21:22], 21:22, xout = 0.9)
approx(data[25:26], 25:26, xout = 0.9)
Your points were close - just a bit high: approx gives
21.31012 and 25.90112.
Peter Ehlers
More information about the R-help
mailing list