0

I have a vector of characters:

x <- c("species1", "species2", "species3")

I would like to add each of these elements in a plot, as a legend, for instance, like this:

legend("topleft", x[1], bty="n")

But here comes my problem: it needs to be in italic.

What I do is to try this:

legend("topright",expression(italic(x[1])), bty="n")

However, instead of getting it in italics the value in x[1] (in this case: "species1"), what I get in italics is the "x[1]" itself!

Is there any way to solve this?

A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
user18441
  • 643
  • 1
  • 7
  • 15

1 Answers1

0

You can use substitute to swap out variables in an expression. This should work

legend("topright",legend=substitute(italic(x), list(x=x[1])), bty="n")
MrFlick
  • 195,160
  • 17
  • 277
  • 295