Kenneth Roy Cabrera Torres
2009-Aug-25 20:30 UTC
[R] math symbol + value of a variable in legend.
Hi R users: I will like to have a legend with math symbols and also with the value of a variable. But I cannot obtain both at the same time (symbol + value of a variable): Here is a reproducible example: m1<-5 m2<-12 plot(1:5,1:5,type="n") legend("topleft",legend=c(paste(expression(mu),"=",m1),expression(paste(mu,"=",m2))),lty=1:2) Thank you for your help. Kenneth PD: Using R 2.9.2 on Linux ubuntu 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18 19:25:34 UTC 2009 x86_64 GNU/Linuxu
On Aug 25, 2009, at 4:30 PM, Kenneth Roy Cabrera Torres wrote:> Hi R users: > > I will like to have a legend with math symbols and also with > the value of a variable. > > But I cannot obtain both at the same time (symbol + value of a > variable): > > Here is a reproducible example: > > m1<-5 > m2<-12I think I am violating a fortune but this "worked": plot(1:5,1:5,type="n") legend ("topleft",legend=c(eval(substitute( expression(paste(mu,"=",m1)), list(m1=m1) )) , eval(substitute( expression(paste(mu,"=",m2)), list(m2=m2) ) )), lty=1:2) And efforts at simplification were at least partly successful: legend("topleft",legend=c(eval(substitute( expression(mu == m1), list(m1=m1) )) , eval(substitute( expression(mu == m2), list(m2=m2) ) )), lty=1:2)> plot(1:5,1:5,type="n") > legend > ("topleft > ",legend > =c(paste(expression(mu),"=",m1),expression(paste(mu,"=",m2))),lty=1:2) > > Thank you for your help. > > Kenneth-- David Winsemius, MD Heritage Laboratories West Hartford, CT
Check out bquote as in this example: https://stat.ethz.ch/pipermail/r-help/2009-August/209373.html On Tue, Aug 25, 2009 at 4:30 PM, Kenneth Roy Cabrera Torres<krcabrer at une.net.co> wrote:> Hi R users: > > I will like to have a legend with math symbols and also with > the value of a variable. > > But I cannot obtain both at the same time (symbol + value of a > variable): > > Here is a reproducible example: > > m1<-5 > m2<-12 > plot(1:5,1:5,type="n") > legend("topleft",legend=c(paste(expression(mu),"=",m1),expression(paste(mu,"=",m2))),lty=1:2) > > Thank you for your help. > > Kenneth > > PD: Using R 2.9.2 on Linux ubuntu 2.6.28-15-generic #49-Ubuntu SMP > Tue Aug 18 19:25:34 UTC 2009 x86_64 GNU/Linuxu > > ______________________________________________ > 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. >
Henrique Dallazuanna
2009-Aug-27 18:42 UTC
[R] math symbol + value of a variable in legend.
Try this: legend("topleft", c(as.expression(bquote(mu == .(m1))), as.expression(bquote(mu == .(m2))))) On Tue, Aug 25, 2009 at 5:30 PM, Kenneth Roy Cabrera Torres < krcabrer@une.net.co> wrote:> Hi R users: > > I will like to have a legend with math symbols and also with > the value of a variable. > > But I cannot obtain both at the same time (symbol + value of a > variable): > > Here is a reproducible example: > > m1<-5 > m2<-12 > plot(1:5,1:5,type="n") > > legend("topleft",legend=c(paste(expression(mu),"=",m1),expression(paste(mu,"=",m2))),lty=1:2) > > Thank you for your help. > > Kenneth > > PD: Using R 2.9.2 on Linux ubuntu 2.6.28-15-generic #49-Ubuntu SMP > Tue Aug 18 19:25:34 UTC 2009 x86_64 GNU/Linuxu > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]