[R] how to compute srt value to text along a line

dinesh dinesh.k.somani at gmail.com
Sat Feb 25 03:50:30 CET 2012


Hi

I want to draw a line between two points p1 and p2 (no problems) and 
then print text it along its path (facing problems). I use  grconvertX() 
to compute the slope E.g.,

     arrows(p1.x, p1.y, p2.x., p2.y); # p2 is on right of p1
     vert = grconvertX( c(p2.y, p1.y), from="user", to="inches" ); # 
also tried to="device"
     horz = grconvertX( c(p2.x, p1.x), from="user", to="inches" );
     srt = 180 * atan( diff(vert) / diff(horz) );
     text( p2.x, p2.y, "this line", pos=2, srt=srt );

However, the text is never exactly aligned with the line. Usually, it's 
a little overtilted. I also tried variously with 
par(c("fin","din","pin","plt")) but same kind of luck.

I was wondering if
- Is there a more appropriate way to compute the srt   parameter?
- is there some other simple function to to write text at a  slope 
matching that of some line?

I am using R2.13.1 on a notebook running Windows 7 64bit.

Thanks
Dinesh at MilkorWater.com



More information about the R-help mailing list