2

I would like to do something like this:

Title<-paste(typis[which.panel],bquote(nu[x]==.(typas[which.panel])),sep="")

where typas is a vector of numbers and typis a vector of chars e.g.:

typas<-1:3
typis<-letters[1:3]

which.panel is an integer in 1:3 (this is because Title will change according to the panel)

and nu[x] should show as a plotmath object. but R ignores everything after the comma in the paste :(

4
  • 1
    So what is which.panel? Commented Jan 24, 2013 at 11:04
  • 1
    What do you want to achieve? Do you want the panel label (typis) followed by the nu[x] bit in a single expression? Commented Jan 24, 2013 at 11:14
  • almost; I want typis[1] followed by nu[x] followed by typas[1]. The first and third should be evaluated, the second not. So the string will be:// "a " $\nu_x=$ 1 // where $\nu_x$ should show a plotmat symbol...is this clear!? Commented Jan 24, 2013 at 11:17
  • @user189035 Check out my Answer, is that what you wanted/meant? Commented Jan 24, 2013 at 11:54

1 Answer 1

3

It isn't immediately clear what you want, but if it is just an expression containing both bits of information, you don't need paste(), just include both bits in the bquote() call and separate them with one or more ~ depending on how much space you want. The key thing to note is that bquote() can take as many different .() as you want to include.

typas <- 1:3
typis <- letters[1:3]
which.panel <- 2
expr <- bquote(.(typis[which.panel]) ~~ nu[x]==.(typas[which.panel]))

plot(1:10, main = expr)

If you need a bit more formatting around the typis part of the expression (say to add a : if this is a panel label), then add this inside the relevant .():

expr2 <-
  bquote(.(paste0(typis[which.panel], ":")) ~~ nu[x]==.(typas[which.panel]))
plot(1:10, main = expr2)

Of course, that could be done outside the expression:

typis2 <- paste0(letters[1:3], ":")
expr3 <- bquote(.(typis2[which.panel]) ~~ nu[x]==.(typas[which.panel]))
plot(1:10, main = expr3)

The three plots look like this:

enter image description here

The last two are essentially equivalent.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks that's exactly what i wanted to know...didn't know of the ~!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.