If I have two variables set, one of which holds an expression, for example: > label <- 'Temperature' > unit <- expression(paste(degree,'C')) how can I join them together for use in mtext (or equivalent)? The following is conceptually what I want to do, but will obviously not work: > plot(0:1) > mtext(paste(label,unit)) Preferably, I would like this to work if one, both or neither of label and unit are expressions. Thanks, Trevor. -- Please consider the environment before printing this email. NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd.
How to join two plotmath type expressions
6 messages · Pascal Oettli, S Ellison, arun +2 more
Hello, Try this one: > mtext(expression(Temperature(degree*C))) Hope this help Regards, Pascal Le 12/08/15 12:56, Trevor Carey-Smith a ?crit :
If I have two variables set, one of which holds an expression, for example:
> label <- 'Temperature' > unit <- expression(paste(degree,'C'))
how can I join them together for use in mtext (or equivalent)? The following is conceptually what I want to do, but will obviously not work:
> plot(0:1) > mtext(paste(label,unit))
Preferably, I would like this to work if one, both or neither of label and unit are expressions. Thanks, Trevor. -- Please consider the environment before printing this email. NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd.
______________________________________________ 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.
> label <- 'Temperature' > unit <- expression(paste(degree,'C'))
how can I join them together for use in mtext (or equivalent)? The following is conceptually what I want to do,
This seems to work:
plot(1:10, type='n')
label <- 'Temperature'
unit <- bquote(degree*C)
text(5,5,substitute(l~u, list(l=label, u=unit)))
S Ellison
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
HI,
Try this:
plot(1:10, type='n')
?newtxt<-bquote(paste("Temperature", "(",degree*C,")",sep=""))
?mtext(newtxt,3)
A.K.
----- Original Message -----
From: Trevor Carey-Smith <trevor.carey-smith at niwa.co.nz>
To: r-help at r-project.org
Cc:
Sent: Tuesday, August 14, 2012 11:56 PM
Subject: [R] How to join two plotmath type expressions
If I have two variables set, one of which holds an expression, for example:
label <- 'Temperature' unit <- expression(paste(degree,'C'))
how can I join them together for use in mtext (or equivalent)? The following is conceptually what I want to do, but will obviously not work:
plot(0:1) mtext(paste(label,unit))
Preferably, I would like this to work if one, both or neither of label and unit are expressions. Thanks, Trevor. -- Please consider the environment before printing this email. NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd. ______________________________________________ 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.
On 08/15/2012 10:45 PM, S Ellison wrote:
label<- 'Temperature' unit<- bquote(degree*C) text(5,5,substitute(l~u, list(l=label, u=unit)))
Thanks, that's exactly what I was after. Regards, Trevor. -- Please consider the environment before printing this email. NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd.
1 day later
On Aug 15, 2012, at 23:17 , Trevor Carey-Smith wrote:
On 08/15/2012 10:45 PM, S Ellison wrote:
label<- 'Temperature' unit<- bquote(degree*C) text(5,5,substitute(l~u, list(l=label, u=unit)))
Thanks, that's exactly what I was after.
A curious application of bquote though. How about using it where it matters? plot(5, 4) label <- 'Temperature' unit <- quote(degree*C) text(5, 5, bquote(.(label) ~ .(unit)))
Regards, Trevor. -- Please consider the environment before printing this email. NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd.
______________________________________________ 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.
Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com