Disclaimer: I have read plotmath, but maybe it's too late today:
How do I get the two labels to be the same: plot.new() lab =expression(paste("Estimated ", t[50]," from tgv")) text(0.5,0.5,lab) # Should look the same as above. I could not get the substitute right: what = "tgv" lab =expression(paste("Estimated ", t[50]," from ",what)) text(0.5,0.2,lab) Dieter ______________________________________________ [hidden email] 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. |
hi,
try this lab =bquote(paste("Estimated ", t[50]," from ",.(what))) HTH, baptiste On 27 August 2010 20:19, Dieter Menne <[hidden email]> wrote: > > plot.new() > lab =expression(paste("Estimated ", t[50]," from tgv")) > text(0.5,0.5,lab) > # Should look the same as above. I could not get the substitute right: > what = "tgv" > lab =expression(paste("Estimated ", t[50]," from ",what)) > text(0.5,0.2,lab) > ______________________________________________ [hidden email] 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. |
In reply to this post by Dieter Menne
On Aug 27, 2010, at 2:19 PM, Dieter Menne wrote: > Disclaimer: I have read plotmath, but maybe it's too late today: > > How do I get the two labels to be the same: > > plot.new() > lab =expression(paste("Estimated ", t[50]," from tgv")) > text(0.5,0.5,lab) > # Should look the same as above. I could not get the substitute right: > what = "tgv" > lab =expression(paste("Estimated ", t[50]," from ",what)) > text(0.5,0.2,lab) The problem with that method (I think) is that expression protects its arguments to some extent. The help page wording is that it is "special" and does not evaluate its arguments although you seem to have gotten the paste() function evaluated. Try: plot.new() lab <- expression(paste("Estimated ", t[50]," from tgv")) text(0.5,0.5,lab) # Should look the same as above. I could not get the substitute right: what <- "tgv" ; expr <- paste("Estimated t[50] from ", what) lab <- as.expression(expr) # expression() does not satisfy text(0.5,0.2,lab) -- David Winsemius, MD West Hartford, CT ______________________________________________ [hidden email] 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. |
Thanks to both of you. I noted that my example was over-simplified. Looks like I need to correct the environment when nested in a function, but I have to catch the last bus now.
Dieter plotExp = function(what) { plot.new() lab =expression(paste("Estimated ", t[50]," from tgv")) text(0.5,0.5,lab) # Should look the same as above. Looks like I need a substitute.... lab =bquote(paste("Estimated ", t[50]," from ",.(what))) ##<<need environment text(0.5,0.2,lab) } plotExp(what) |
In reply to this post by baptiste auguie-5
On Aug 27, 2010, at 2:28 PM, baptiste auguie wrote: > hi, > > try this > > lab =bquote(paste("Estimated ", t[50]," from ",.(what))) bquote doesn't need the paste() if you use plotmath separators: lab =bquote(Estimated ~t[50]~from~.(what)) text(0.5,0.2,lab) > > > HTH, > > baptiste > > On 27 August 2010 20:19, Dieter Menne <[hidden email]> > wrote: >> >> plot.new() >> lab =expression(paste("Estimated ", t[50]," from tgv")) >> text(0.5,0.5,lab) >> # Should look the same as above. I could not get the substitute >> right: >> what = "tgv" >> lab =expression(paste("Estimated ", t[50]," from ",what)) >> text(0.5,0.2,lab) >> David Winsemius, MD West Hartford, CT ______________________________________________ [hidden email] 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. |
In reply to this post by Dieter Menne
On Aug 27, 2010, at 2:51 PM, Dieter Menne wrote: > > Thanks to both of you. I noted that my example was over-simplified. > Looks > like I need to correct the environment when nested in a function, > but I have > to catch the last bus now. > > Dieter > > > plotExp = function(what) { > plot.new() > lab =expression(paste("Estimated ", t[50]," from tgv")) > text(0.5,0.5,lab) > # Should look the same as above. Looks like I need a substitute.... > lab =bquote(paste("Estimated ", t[50]," from ",.(what))) ##<<need > environment > text(0.5,0.2,lab) > } > plotExp(what) > Hope you caught the bus. Doesn't appear that an environment is needed if you don't add the paste() operation: what= "tgv" plotExp <- function(what) { plot.new() lab =expression(paste("Estimated ", t[50]," from tgv")) text(0.5,0.5,lab) lab =bquote(Estimated~t[50]~ from ~.(what) ) ; text(0.5,0.2,lab) } plot(what) Furthermore I could not see from what infirmities the first version suffered. David Winsemius, MD West Hartford, CT ______________________________________________ [hidden email] 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. |
For the record: lattice behaves slightly differently, it requires an "as.expression" with bquote.
Dieter plotExp <- function(what) { plot.new() lab = bquote(Estimated~t[50]~ from ~.(what) ) ; text(0.5,0.2,lab) } plotExp("tgv") library(lattice) plotLattice <- function(what) { lab = bquote(Estimated~t[50]~ from ~.(what) ) ; # Note that ylab is wrong, xlab is correct xyplot(1~1,xlab=as.expression(lab), ylab=lab) } plotLattice("tgv") |
Powered by Nabble | Edit this page |