plotmath: paste string and expression [from a vectorof expressions]
-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Marius Hofert
Sent: Thursday, June 02, 2011 1:20 PM
To: Uwe Ligges
Cc: Help R
Subject: Re: [R] plotmath: paste string and expression [from
a vectorof expressions]
Dear Uwe,
thanks for your help. Actually, I first thought about writing
your solution in the email in order to make clear that it is
not the solution I'm looking for :-) My goal is to work with
the vector "vars" of expressions. The example is only a
minimal example and for that your solution is perfectly fine,
but my original problem is more complicated and there it
makes sense to work with a vector of expressions. Do you know
a solution to that? I tried many things... the obvious
plot(0, 0, main=substitute(bold("Foo" ~~ VAR),
list(VAR=vars[2]) )) did not work...
Use VAR=vars[[2]] (double brackets) there. You can see the
difference if you look at the output of your call to substitute.
[[ gives you an element of the expression and [ gives you
an expression containing an element:
> substitute(bold("Foo" ~~ VAR), list(VAR=vars[[2]]) )
bold("Foo" ~ ~beta)
> substitute(bold("Foo" ~~ VAR), list(VAR=vars[2]) )
bold("Foo" ~ ~expression(beta))
The same holds for the bquote() solution that David W. suggested.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
Cheers, Marius On 2011-06-02, at 22:14 , Uwe Ligges wrote:
On 02.06.2011 20:43, Marius Hofert wrote:
Dear all, I have a vector of expressions and would like to "paste"
some string to it before using it in a plot:
vars<- vector("expression", 2)
vars[1]<- expression(alpha)
vars[2]<- expression(beta)
plot(0, 0, main=substitute(bold("Foo" ~~ VAR), list(VAR=vars[2]) ))
Although I tried hard, I just can't figure out how to
solve this. The title should be "Foo<theta>", where<theta> is the greek letter. I tried some constructions with bquote but that wasn't successful... I also looked in the mailing list but couldn't find anything helpful [I am sure I overlooked something].
plot(0, 0, main=expression("Foo" ~~ theta))
Uwe Ligges
Cheers, Marius
______________________________________________ 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. ______________________________________________ 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.