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
baptiste auguie
2010-Aug-27 18:28 UTC
[R] How to plot an expression-label with variable text
hi, try this lab =bquote(paste("Estimated ", t[50]," from ",.(what))) HTH, baptiste On 27 August 2010 20:19, Dieter Menne <dieter.menne at menne-biomed.de> 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
2010-Aug-27 18:40 UTC
[R] How to plot an expression-label with variable text
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
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) -- View this message in context: http://r.789695.n4.nabble.com/How-to-plot-an-expression-label-with-variable-text-tp2341465p2341499.html Sent from the R help mailing list archive at Nabble.com.