perep1972
perep1972

Reputation: 147

R language italicize iteratively gera

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?

Upvotes: 2

Views: 52

Answers (2)

mt1022
mt1022

Reputation: 17289

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

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

enter image description here

Upvotes: 2

Sinh Nguyen
Sinh Nguyen

Reputation: 4487

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

Upvotes: 2

Related Questions