[R] Text position in Traditional Graphics

2007-01-24 Thread Mike Prager
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.

Thanks!

-- 
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Text position in Traditional Graphics

2007-01-24 Thread Charles Annis, P.E.
A few days a go Jim Holman [EMAIL PROTECTED] 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

x-c(0,1)
plot(x,x,type='l')
dimensions-matrix(c(strwidth(expression(theta),cex=5),strheight(expression(
theta),
cex=5)),nrow=1)
symbols(0.5,0.5
,rectangle=dimensions,bg='white',fg='white',add=TRUE,inches=FALSE)
text(0.5,0.5,expression(theta),cex=5)
~



Charles Annis, P.E.

[EMAIL PROTECTED]
phone: 561-352-9699
eFax:  614-455-3265
http://www.StatisticalEngineering.com
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mike Prager
Sent: Wednesday, January 24, 2007 4:30 PM
To: r-help@stat.math.ethz.ch
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.

Thanks!

-- 
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Text position in Traditional Graphics

2007-01-24 Thread Marc Schwartz
On Wed, 2007-01-24 at 16:30 -0500, Mike Prager wrote:
 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.
 
 Thanks!

Mike, you might want to take a look at:

  ?strheight

The one thing to be potentially aware of, is if the plot window is
resized, some aspects of drawing text can be subject to alteration. It
may take some trial and error to determine how the method you wish to
use may be prone to such problems.

For example:

 plot(1, type = n)
 text(1, 1, This is a test)
 text(1, 1 + strheight(T), This is a test)
 text(1, 1 + strheight(T) * 2, This is a test)
 text(1, 1 + strheight(T) * 3, This is a test)

Now, drag and resize the plot window here

Then run:

  text(1, 1 + strheight(T) * 4, This is a test)

This may behave differently on Windows, but on Linux, when I resize the
X window, the last line of text (* 4) is placed between (* 2) and (* 3).

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Text position in Traditional Graphics

2007-01-24 Thread Mike Prager
Mike Prager [EMAIL PROTECTED] wrote:

 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()? 
[...]

I seem to have solved my own question by setting the user scale
to the size of the window in inches, converting the point size
into inches, and going from there.  This works well for all
sizes of windows. It doesn't change the spacing when windows are
resized, but I can live with that.

There is nothing like posting to R-help to stimulate one's own
thoughts.

-- 
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Text position in Traditional Graphics

2007-01-24 Thread Greg Snow
If you are going to take this approach, you may want to look at the
cnvrt.coords function in the TeachingDemos package.  That may save you a
few calculations.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Mike Prager
 Sent: Wednesday, January 24, 2007 3:01 PM
 To: r-help@stat.math.ethz.ch
 Subject: Re: [R] Text position in Traditional Graphics
 
 Mike Prager [EMAIL PROTECTED] wrote:
 
  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()?
 [...]
 
 I seem to have solved my own question by setting the user 
 scale to the size of the window in inches, converting the 
 point size into inches, and going from there.  This works 
 well for all sizes of windows. It doesn't change the spacing 
 when windows are resized, but I can live with that.
 
 There is nothing like posting to R-help to stimulate one's 
 own thoughts.
 
 --
 Mike Prager, NOAA, Beaufort, NC
 * Opinions expressed are personal and not represented otherwise.
 * Any use of tradenames does not constitute a NOAA endorsement.
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.