Hello, I have to add "Age (bar(x)=14.3) as a title on a chart. I am unable to get this to working. I have tried bquote, substitute and expression, but they are only doing a part of the job. new<- c(14.3, 18.5, 18.1, 17.7, 18, 15.9, 19.6, 17.3, 17.8, 17.5, 15.4, 16.3, 15, 17.1, 17.1, 16.4, 15.2, 16.7, 16.7, 16.9, 14.5, 16.6, 15.8, 15.2, 16.2, 15.6, 15, 17.1, 16.7, 15.6, 15, 15.8, 16.8, 17, 15.2, 15.8, 15.7, 14.7, 17.3, 14.9, 16.8, 14.6, 19.3, 15.3, 14.7, 13.3, 16.5, 16, 14.2, 16.1, 15.2, 13.4, 17.7, 15.5, 14.5, 15.7, 13.6, 14.1, 20, 17.2, 16.5, 14.3, 13.7, 14.7, 15.4, 13.6, 17, 17.3, 15.4, 15.5, 16.6, 15.8, 15.7, 14.7, 14.2, 14.2, 14, 14.2, 19.1, 17.2, 18.3, 13.9, 16, 15.9, 14.9, 14.6, 15.9, 12.2, 14.1, 12, 12.8, 17.1, 17, 15, 15.8, 15.9, 16.1, 18, 14.7, 18.9 ) hist(new, xlab='30-day Death Rate',xlim=c(7,22),main=expression("Heart Attack(" * bar(X) * ")=" * mean(new))) I would appreciate any pointers on getting this correct. Thanks -- View this message in context: http://r.789695.n4.nabble.com/characters-mathematical-expressions-and-computed-values-tp4645916.html Sent from the R help mailing list archive at Nabble.com.
William Dunlap
2012-Oct-11 23:23 UTC
[R] characters, mathematical expressions and computed values
I think that bquote, with its .() operator, suffices for [almost?] any single title; don't bother fiddling with expression(), substitute(), or parse(). (You can make those work in many situations, but if you stick with just bquote then you can spend your time on the title itself.) E.g., hist(new, main=bquote("Heart Attack (" * bar(X)==.(mean(new)) * ")")) or, if you want to limit the number of digits after the decimal point, hist(new, main=bquote("Heart Attack (" * bar(X)==.(round(mean(new),1)) * ")")) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf > Of 1Rnwb > Sent: Thursday, October 11, 2012 2:32 PM > To: r-help at r-project.org > Subject: [R] characters, mathematical expressions and computed values > > Hello, > > I have to add "Age (bar(x)=14.3) as a title on a chart. I am unable to get > this to working. I have tried bquote, substitute and expression, but they > are only doing a part of the job. > > new<- > c(14.3, 18.5, 18.1, 17.7, 18, 15.9, 19.6, 17.3, 17.8, 17.5, 15.4, > 16.3, 15, 17.1, 17.1, 16.4, 15.2, 16.7, 16.7, 16.9, 14.5, 16.6, > 15.8, 15.2, 16.2, 15.6, 15, 17.1, 16.7, 15.6, 15, 15.8, 16.8, > 17, 15.2, 15.8, 15.7, 14.7, 17.3, 14.9, 16.8, 14.6, 19.3, 15.3, > 14.7, 13.3, 16.5, 16, 14.2, 16.1, 15.2, 13.4, 17.7, 15.5, 14.5, > 15.7, 13.6, 14.1, 20, 17.2, 16.5, 14.3, 13.7, 14.7, 15.4, 13.6, > 17, 17.3, 15.4, 15.5, 16.6, 15.8, 15.7, 14.7, 14.2, 14.2, 14, > 14.2, 19.1, 17.2, 18.3, 13.9, 16, 15.9, 14.9, 14.6, 15.9, 12.2, > 14.1, 12, 12.8, 17.1, 17, 15, 15.8, 15.9, 16.1, 18, 14.7, 18.9 > ) > hist(new, xlab='30-day Death Rate',xlim=c(7,22),main=expression("Heart > Attack(" * bar(X) * ")=" * > mean(new))) > > I would appreciate any pointers on getting this correct. > Thanks > > > > -- > View this message in context: http://r.789695.n4.nabble.com/characters-mathematical- > expressions-and-computed-values-tp4645916.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.
S Ellison
2012-Oct-12 12:35 UTC
[R] characters, mathematical expressions and computed values
> [mailto:r-help-bounces at r-project.org] On Behalf Of William Dunlap > Subject: Re: [R] characters, mathematical expressions and computed values > > I think that bquote, with its .() operator, suffices for > [almost?] any single title; > ... > E.g., > hist(new, main=bquote("Heart Attack (" * bar(X)==.(mean(new)) * ")"))In this instance, using hist(new, main=bquote( "Heart Attack " * (bar(X) ==.( mean(new) )) ) ) improves the parentheses slightly, as it uses plotmath parentheses instead of forcing text parentheses. Otherwise I agree completely; bquote is a neat way of doing the job. S Ellison ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
mee1d3hs
2012-Nov-23 20:20 UTC
[R] characters, mathematical expressions and computed values
The code hist(new, main=bquote("Heart Attack (" * bar(X)==.(round(mean(new),1)) * ")")) does not work on 2.15.2 on OSX. the histogram is generated, but the title does show at all, which kind of tells me the bquote expression is failing I would appreciate any help in making this work, it seems it should be easy, but somehow it is not. I tried using substitute, and many other ways with no help -- View this message in context: http://r.789695.n4.nabble.com/characters-mathematical-expressions-and-computed-values-tp4645916p4650589.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2012-Nov-24 00:23 UTC
[R] characters, mathematical expressions and computed values
On Nov 23, 2012, at 12:20 PM, mee1d3hs wrote:> The code > > hist(new, main=bquote("Heart Attack (" * bar(X)==.(round(mean(new), > 1)) * > ")")) > > does not work on 2.15.2 on OSX. the histogram is generated, but the > title > does show at all, which kind of tells me the bquote expression is > failingWorks fine for me. I just updated to 2.15.2 today. Used 1:4 as the value for new and got he correct title.> > I would appreciate any help in making this work, it seems it should > be easy, > but somehow it is not. I tried using substitute, and many other ways > with no > help> sessionInfo() R version 2.15.2 (2012-10-26) Platform: i386-apple-darwin9.8.0/i386 (32-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] survey_3.29 ggplot2_0.9.2.1 loaded via a namespace (and not attached): [1] colorspace_1.2-0 dichromat_1.2-4 digest_0.5.2 [4] grid_2.15.2 gtable_0.1.1 labeling_0.1 [7] MASS_7.3-22 memoise_0.1 munsell_0.4 [10] plyr_1.7.1 proto_0.3-9.2 RColorBrewer_1.0-5 [13] reshape2_1.2.1 scales_0.2.2 stringr_0.6.1 [16] tools_2.15.2 David Winsemius, MD Alameda, CA, USA