Re: [R] Rotated text on a regression line

From: Charilaos Skiadas <>
Date: Tue, 27 May 2008 17:52:05 -0400

I think this comment for ?par, meant for both crt and srt, applies:

A numerical value specifying (in degrees) how single characters should be rotated. It is unwise to expect values other than multiples of 90 to work. Compare with srt which does string rotation.

So I would say that even getting close to the right angle is not bad. I would think that perhaps the graphics devices can only write in particular directions, and that's the one closest to your graph.

Actually, further playing with it, I think all you are missing is that this angle is not dependent on the aspect ratio, it's an absolute angle. Try to resize the window, and see how the direction of the string does not change at all, even though the line slope does change.

Hence the advice about only relying on 0 and 90 degrees.

Haris Skiadas
Department of Mathematics and Computer Science Hanover College

On May 27, 2008, at 5:25 PM, Dr. Christoph Scherber wrote:

> Dear all,
> I stumbled over a problem recently when trying to use srt with text
> () on a
> windows device.
> What I intended to do was to plot a simple regression line, and to
> rotate
> a piece of text such that the text has the same angle as the
> regression
> line.
> However, the text is always plotted in a slightly wrong angle:
> ####
> x=1:10 #create arbitrary x and y values
> y=x*2-rnorm(1:10)
> plot(x,y,pch=16,xlim=c(0,10)) #create the graph
> abline(lm(y~x))
> #calculate the y coordinate of the text:
> yval=predict(lm(y~x),list(x=rep(2,length(x))))[1]
> #calculate the slope:
> slope=as.numeric(lm(y~x)[[1]][2])
> text(2,yval,"Regression",srt=180/pi*atan(slope),adj=0)
> ####
> What am I doing wrong here?
> Many thanks in advance for any help!
> Best wishes
> Christoph
> (using R 2.6.1 on Windows XP)
> mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue 27 May 2008 - 22:27:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 27 May 2008 - 22:30:45 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive