1

a want to plot some graphs from for loop, where the main should be half italic and half normal. The code example should be

 a1<-1:20
 a2<-sample(a1)
 b1<-sample(a1)
 b2<-sample(a1)
 a<-list(a1, a2)
 b<-list(b1, b2)
 v<-c("a", "b")
 for(i in 1:2){
 jpeg(file=sprintf("%s.jpg", v[i]))
 plot(a[[i]], b[[i]], main=c("sas", v[i]))
 dev.off()}

but the v[i] should be in italic. I tried

 plot(a[[i]], b[[i]], main=c("sas", expression(italic(v[i]))))

but the second line of main is missing. Thx for any ideas!

Bobesh
  • 1,157
  • 2
  • 15
  • 30

1 Answers1

2

How about

 plot(a[[i]], b[[i]], main=bquote("sas"~italic(.(v[i]))))

That produces

enter image description here

Of if you realy wanted two lines, you could do

plot(a[[i]], b[[i]], main=bquote(atop("sas",italic(.(v[i])))))
MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • `bquote()` (and the sister function `substitute()`) is useful anytime you need to dynamically build an expression. Adding formatting and math symbols to plots usually requires expressions. – MrFlick Feb 25 '16 at 16:23