How to write text along a line or curve in R?

I have a dataset and am trying to set a linear model using lm() . This part is straightforward.

I can also construct this correspondence to the scatter plot graph using abline( lm( x ~ y ) ) .

But now I want to write fit parameters, such as adjusted r-squared along the line.
Therefore, if I find a graph of various data sets and their corresponding sets, I should be able to print some values ​​for line correspondence.

Is it possible to do this in R.

+4
source share
1 answer

Yes, it’s easy to do for straight lines, the curve is harder, perhaps easier with monospaced fonts. The basic technique would be to simply transform your linear equation so that you can get the polar expression at an angle. Use this angle to set the angle of the text in the text command using the srt argument (from graphic options).

For a curve, this would be a bit more complicated (possibly simplified by disproportionate fonts). You need to work out vectors for each letter with an angle, and then across the width of each character (using strwidth ). You must generate a vector of angles and positions for your characters and scroll through them, calling text . You need a loop here because text cannot take a vector for the srt argument.

+3
source

All Articles