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.
characters, mathematical expressions and computed values
5 messages · 1Rnwb, William Dunlap, S Ellison
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.
[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}}
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121012/f4f72960/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121012/3541cc8e/attachment.pl>