John Miyamoto
2002-Feb-10 05:41 UTC
[R] text that combines math expressions and numeric variables
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Paul Murrell
2002-Feb-10 21:01 UTC
[R] text that combines math expressions and numeric variables
Hi> 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.The vertical alignment of the mathematical annotations is wrong -- it should be treating adj=0 as adj=c(0, 0.5). In other words, when a vertical adjustment is not explicitly given, it should centre vertically. At the moment, when a vertical adjustment is not given, it is bottom-adjusting (so to speak) i.e,. it is treating adj=0 as adj=c(0, 0). A work around for this is to use adj=c(0, 0.5) i.e., explicitly specify vertical centring. I will add a proper fix for the next R release. I think there was a similar report about vertical alignment of mathematical annotation on R-help recently. Can anyone confirm/point me to that? Paul -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._