Using italics in the title on an object from a dataframe

2.1k views Asked by At

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!

1

There are 1 answers

0
akrun On BEST ANSWER

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)))))