6

Using R 2.14.0 with windows 7, I want to include italics and a changing variable in my title using R plot(). Here's some code:

ps=c(1,2,3)

layout(matrix(1:3,1,3))

#this works but isn't what I want
for(i in 1:3){
    plot(1,1,main=expression(paste(italic(p),'=5')))
}
#this doesn't work
for(i in 1:3){
    plot(1,1,main=expression(paste(italic(p),'=',ps[i])))
}
#this doesn't work either
for(i in 1:3){
    plot(1,1,main=paste(expression(paste(italic(p),'=')),ps[i]))
}

What I want in the title is p[in italics]=the value of ps during that iteration. For instance for the first iteration, "p=0.1"

Any help would be appreciated. Thanks.

user1260251
  • 83
  • 1
  • 1
  • 8

1 Answers1

6

Does this help?

ps=c(1,2,3)
layout(matrix(1:3,1,3))
for(i in 1:3){
    plot(1,1,main=substitute(paste(italic(p), " = 0.", x, sep=""), list(x=ps[i])))
}

Also have a look at this this question.

Community
  • 1
  • 1
johannes
  • 14,043
  • 5
  • 40
  • 51
  • 6
    The sep argument to plotmath `paste` is not needed. And a simple method would dispense with `paste` and the hokey "0." and just use bquote: main=bquote( italic(p)==.(ps[i]/10) ) – IRTFM Mar 14 '12 at 19:07