0
paste("foo", 0:5, sep = "")

returns a sequence of numbered strings. Similarly,

sprintf("foo%d", 0:5)

achieves the same result. But suppose I'd like to replace "foo" with a special character (the Greek character lambda, for example), such that the desired output is the same as returned from the call below

c( expression(lambda*0), expression(lambda*1) ) # ... and so on

How could I achieve this? Can I do it by modifying either of first two calls?

Some attempts that don't work:

expression(paste(lambda, 0:5)) # returns a single string, 'lambda'0:5

paste(expression(lambda), 0:5)) # doesn't return the character

sprintf(bquote("expression(lambda)%d"), 0:5) # at this point I've exhausted my sense

This is intended for a plot legend, by the way. Thank you!

pyg
  • 716
  • 6
  • 18
  • How is this: `Map(as.expression,sprintf("lambda * %d",1:5))`? – Abdou Sep 09 '16 at 10:47
  • `barplot(1:5, names.arg = parse(text = paste('lambda', 1:5, sep = '*')))` – rawr Sep 09 '16 at 10:48
  • also possible duplicate: http://stackoverflow.com/questions/5293715/how-to-use-greek-symbols-in-ggplot2 – yoland Sep 09 '16 at 10:54
  • Thank you all for your help. @rawr, your solution works perfectly. If you offer it as an answer I'll accept. – pyg Sep 10 '16 at 02:15
  • @Abdou, I couldn't get your solution to work as desired. In a legend it returns a sequence of 'expression("lambda * 1")' etc – pyg Sep 10 '16 at 02:15

0 Answers0