[R] Rotated text on a regression line

Dr. Christoph Scherber Christoph.Scherber at agr.uni-goettingen.de
Wed May 28 00:00:50 CEST 2008


Thanks to all for the postings so far!

I found that setting asp=0.5 and then dividing the slope by 2 seems to do
the trick:

##

x=1:10
y=x*2-rnorm(1:10)

plot(x,y,pch=16,asp=0.5)
abline(lm(y~x))
yval=predict(lm(y~x),list(x=rep(2,length(x))))[1]
slope=as.numeric(lm(y~x)[[1]][2])
text(2,yval,"Regression",srt=180/pi*atan(slope/2),adj=0)

##

This might be a way of controlling for the aspect ratio witho8ut producing
"ugly" figures.



More information about the R-help mailing list