2

Sorry for the very stupid question, I have been googleing for a while without finding a solution. I need to create several plots iteratively, whose titles are (1) picked from a previously created vector and (2) must be italicized. I have tried several options with no adequate results, stuff like this:

# Main titles
m <- paste(LETTERS[1:10], LETTERS[11:20])
# Plots
for(i in 1:10){
     x <- runif(10, 1, 20)
     y <- runif(10, 1, 20)
     X11()
     plot(x,y, main = expression(italic(m[i])))
}

But what I got are plots with an "m" with an "i" as a subscript, not the corresponding content in the vector. Any idea?

perep1972
  • 147
  • 1
  • 9

2 Answers2

2

Here is the way to achieve what you want

# Main titles
m <- paste(LETTERS[1:10], LETTERS[11:20])
# Plots
for(i in 1:10){
  x <- runif(10, 1, 20)
  y <- runif(10, 1, 20)
  X11()
  plot(x,y, main = substitute(paste(italic(x)), list(x = m[i])))
}

One of the plots enter image description here

Sinh Nguyen
  • 4,277
  • 3
  • 18
  • 26
2

Another option is to use bquote. The expression in .() will be evaluated:

plot(x,y, main = bquote(italic(.(m[i]))) )

enter image description here

mt1022
  • 16,834
  • 5
  • 48
  • 71