[R] Alignment when rotating text and symbols
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Jul 29 12:26:56 CEST 2003
On Tue, 29 Jul 2003, p.b.pynsent wrote:
> I wanted to annotate some points on lines, above and below the lines.
> I thought the easiest way would be to use text() and two pos values.
> However I found when the text was rotated the space and alignment
> between the point and the text did not remain constant. The following
> code illustrates the problem:
You are rotating the text about its centre, but pos is not in the
rotated frame, as I read it, so why should this be rotation-invariant?
Try
> plot(1:10, type="n")
> text(5,5, "a bit of text")
> text(5,5, "a bit of text", pos=1)
> text(5,5, "a bit of text", pos=1, srt=45)
to see the effect of pos and srt. You go down then rotate, not rotate and
then go down.
> x <- c(0,10.)
> y <- c(0,10.)
> offset <- 3
> centre <- 5
> plot(x,y, xlim=range(x), ylim=range(y),type="n", xlab="",ylab="",
> main="",xaxt="n",yaxt="n")
> for (i in (seq(0, 340, by=45)) )
> {
> px <- centre + cos((i*pi)/180) * offset
> py <- centre + sin((i*pi)/180) * offset
> text(px, py,
> labels=substitute(that%->%phantom(1),list(that=i)), pos=1, col="blue",
> cex=0.7, srt=i)
> text(px, py,
> labels=substitute(that%<-%phantom(1),list(that=i)), pos=3,
> col="blue",cex=0.7,srt=i)
> lines(px, py, type="p", col="black") #just for reference
> }
> What have I done wrong?
> In addition, on my screen, the arrow symbols do not rotate at all
> although they do on the pdf image.
> (R version 1.71, MacOS X 10.2.6)
*WHICH* Mac port of R? There are two!
The lack of rotation is a limitation of the (unspecified) graphics device
of your (unspecified) port, whichever it is: it works on Linux and
Windows, for example, so I would expect this to work on an X11 device on
the Darwin port.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list