Marius Hofert
2011-Jun-02 18:43 UTC
[R] plotmath: paste string and expression [from a vector of expressions]
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]. Cheers, Marius
Uwe Ligges
2011-Jun-02 20:14 UTC
[R] plotmath: paste string and expression [from a vector of expressions]
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.
Dennis Murphy
2011-Jun-02 20:23 UTC
[R] plotmath: paste string and expression [from a vector of expressions]
Hi: This seems to work: vars2 <- c(quote(alpha), quote(beta)) # returns a list of mode call plot(0, 0, main = bquote(bold('Foo '~.(vars2[[2]])))) Expressions are only evaluated once, which means that inner expressions are not evaluated. You need a call object rather than an expression inside of bquote(). HTH, Dennis On Thu, Jun 2, 2011 at 11:43 AM, Marius Hofert <m_hofert at web.de> 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]. > > 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. >
Seemingly Similar Threads
- lattice + plotmath: how to get a variable in bold face?
- how to make plotmath expression work together with paste
- splom, plotmath: how to add three lines of information with alignment?
- How to use expression(italic()) in a "vectorized" way (within a function)?
- Expressions from boxplot() passed to bxp()