Re: [R] Text position in Traditional Graphics

From: Charles Annis, P.E. <>
Date: Wed 24 Jan 2007 - 21:53:49 GMT

A few days a go Jim Holman [] suggested this (Re: [R] How to annotate a graph with non-transparent math labels?) for a similar circumstance. Perhaps it will for in your case.

try using strwidth & strheight

dimensions<-matrix(c(strwidth(expression(theta),cex=5),strheight(expression( theta),
,rectangle=dimensions,bg='white',fg='white',add=TRUE,inches=FALSE) text(0.5,0.5,expression(theta),cex=5)

Charles Annis, P.E. phone: 561-352-9699
eFax: 614-455-3265  

-----Original Message-----
[] On Behalf Of Mike Prager Sent: Wednesday, January 24, 2007 4:30 PM To:
Subject: [R] Text position in Traditional Graphics

R 2.4.1 on Windows XP.

Question: In traditional graphics, is it possible to find out the height of a line of text in units that can be used in arithmetic and then in calls to text()?

Context: I have written a function that draws a plot and then, depending on whether some arguments are TRUE or FALSE, draws various lines of text in the plot. The text lines may be turned on or off individually by the user. The function uses plot() and several calls to text().

However, I have not found a good way to adjust the Y coordinate of the text for lines after the first. I would like this to work when the graphics device (windows) is opened at (or resized to) a wide range of sizes. The issue is that a line of text takes up a smaller fraction of the total Y span of the plotting region as the window gets larger.

It seems this can be done with grid graphics, but although I plan to learn grid, I am hoping that for now, I can do this work with traditional graphics.


Mike Prager, NOAA, Beaufort, NC

* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.
______________________________________________ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. ______________________________________________ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code.
Received on Thu Jan 25 14:32:20 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 25 Jan 2007 - 04:30:33 GMT.

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