1

I want to plot names that come from a dataframe in italic as a ylab. The solution at R plot: Using italics and a variable in a title does not work in this case. Using substitute or expression R literally reads my code

e.g. substitute (paste 'Species = ', italic (rownames (genR) [i]))

will come out in the test as:

Species = rownames (genR)[1]

and I wanted

Species = Musa paradisiaca

Any advice?

Many thanks!

Community
  • 1
  • 1
AEM
  • 919
  • 1
  • 9
  • 22
  • Should have been: `substitute( paste ('Species = ', italic (val) ), list(val = rownames (genR) [i]) )`. If you don't give `substitute` a value to substitute, it can't do anything. – IRTFM Dec 03 '14 at 09:20
  • It really was a duplicate. You just didn't apply the answer as it was illustrated. – IRTFM Dec 03 '14 at 09:27

1 Answers1

3

You could try bquote

 nm1 <- 'Musa paradisiaca'
 plot(1,1, main=bquote('Species = '~italic(.(nm1))))

enter image description here

Update

Or using substitute

 plot(1,1, main=eval(substitute(expr=expression(paste('Species = ',
                              italic(x))), env=list(x=as.name(nm1)))))
Community
  • 1
  • 1
akrun
  • 874,273
  • 37
  • 540
  • 662