[R] text that combines math expressions and numeric variables

John Miyamoto jmiyamot at u.washington.edu
Sun Feb 10 06:41:24 CET 2002


Dear R-Help,
   I have some questions relating to math notation in text functions.  I
have studied the help for plotmath but have not figured out how to solve
two types of problems.

PROBLEM 1:  How can I create expressions that mix mathematical notation,
numeric variables, and ordinary text.  For example,

B0 <- 20;  B1 <- .25
plot(0:100, 0:100, type="n")
text(30, 90, substitute(hat(beta)[0] == this, list(this=B0)) , adj=0)
#Text1
text(25, 90, "Text 1", adj=1)
text(30, 70, paste("beta.0 =", B0, "and beta.1 =", B1), adj=0)   #Text2
text(25, 70, "Text 2", adj=1)
text(30, 50, substitute(hat(beta)[0] == this + hat(beta)[1] == that,
#Text3
     list(this=B0, that=B1)), adj=0)
text(25, 50, "Text 3", adj=1)

Text1 plots the combination of math notation and a numeric variable but it
does not contain ordinary text.  Text2 shows what I would like to
accomplish, except that I would like replace "beta.1" and "beta.2" with
subscripted greek symbols.  Text3 shows something that is almost what I
want, except that I would like to replace the "+" symbol with "and".  I am
also puzzled by the fact that mathematical notation plots higher on the
Y-axis than does the corresponding text.

PROBLEM 2:  How can I force a mathematical expression to move to a new
line, analogous to embedding a carriage return into the expression?  For
example,

B0 <- 20;  B1 <- .25
plot(0:100, 0:100, type="n")
text(30, 70, paste("beta.0 =", B0, "\nbeta.1 =", B1), adj=0)   #Text1
text(25, 70, "Text 1", adj=1)
text(30, 50, substitute(hat(beta)[0] == this, list(this=B0)), adj=0)
#Text2
text(30, 40, substitute(hat(beta)[1] == this, list(this=B1)), adj=0)
#Text2
text(25, 50, "Text 2", adj=1)

Text1 shows what I would like to accomplish except that I would like to
replace "beta.1" and "beta.2" with subscripted greek symbols.  Text2 shows
what I want as output, but I have been forced to explicitly state the
Y-coordinates of the two lines of Text2.  This requires that I know the
scale on the Y-axis.  What I want is to embed a carriage return, "\n",
into the mathematical expression so that I can create a mathematical
expression on multiple lines.  Is this possible?

Any help would be much appreciated.

John Miyamoto


--------------------------------------------------------------------
John Miyamoto                           |
Department of Psychology, Box 351525    |  If ignorance is bliss,
University of Washington                |  why are so many people
Seattle, WA 98195-1525.                 |  unhappy?
Phone: 206-543-0805, Fax: 206-685-3157  |
Email: jmiyamot at u.washington.edu        |
--------------------------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list