[R] Combining math and variables in expression

Greg Snow Greg.Snow at imail.org
Wed Mar 11 17:25:51 CET 2009


> tmp <- '120.000'
> mtext(bquote( '100% Area' == .(tmp)~km^2 ))

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of socrates
> Sent: Wednesday, March 11, 2009 8:08 AM
> To: r-help at r-project.org
> Subject: [R] Combining math and variables in expression
> 
> 
> I am trying to get the following line in a plot margin using mtext:
> 
> 100% Area = 120.000 km^2
> 
> Where I intend that "100% Area =" is text, 120.000 is a number that
> varies
> according to different data, and km^2 should be a neat
> km-with-superscript-2.
> The expression function fails me, since it apparently cannot coerce an
> expression when a variable is involved.
> In the R help file there is an example using either bquote or
> substitute to
> accomplish like things, but these are sufficiently different from my
> objective and I am becoming more and more confused by every further
> example
> I stumble on.
> This should be easy. Can anyone help me prevent spending anoter 2.5
> hours on
> the matter? Thanks.
> --
> View this message in context: http://www.nabble.com/Combining-math-and-
> variables-in-expression-tp22455877p22455877.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org 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.




More information about the R-help mailing list