2

I want to create a plot title "Case1, \xi_{DES}", where \xi is the greek letter, DES must be a subscript, and "Case1" is actually stored in a variable. Following

expression + variable value + normal text in plot maintitle

I tried

Case="Case1"
x=1:3
y=rnorm(3)
plot(x,y, cex=1.5, cex.lab=1.5, 
pch=16, xlab="degree", ylab=expression(italic(paste("|",hat(F),"|"))),
main=bquote(.(Case) ~ , eta[DES]), col="tomato",log="y")

But this doesn't work. The following sort of works:

plot(x,y, cex=1.5, cex.lab=1.5, 
pch=16, xlab="degree", ylab=expression(italic(paste("|",hat(F),"|"))),
main=bquote(.(Case) ~  eta[DES]), col="tomato",log="y")

But I had to eliminate the comma. Why is that? Is there a way to get the title I want in R?

Community
  • 1
  • 1
DeltaIV
  • 4,353
  • 8
  • 33
  • 78
  • 1
    Try `plot(x,y, cex=1.5, cex.lab=1.5, pch=16, xlab="degree", ylab=expression(italic(paste("|",hat(F),"|"))), main=bquote(.(Case)*","* ~ eta[DES]), col="tomato",log="y")` – akrun Dec 11 '15 at 14:40

1 Answers1

5

In case you don't know (it's not easy to find), the documentation is in help("plotmath"):

par(mar = c(5, 5.5, 4, 2) + 0.1)
plot(x,y, cex=1.5, cex.lab=1.5, 
     pch=16, xlab="degree", ylab=expression(italic(group("|",hat(F),"|"))),
     main=bquote(.(Case)*","~xi[{DES}]), col="tomato",log="y")

resulting plot

Roland
  • 122,144
  • 10
  • 182
  • 276
  • Nice! However, instead than `*` I used `paste` - this is more similar to typical uses of `expression`. In other words, I used `main=bquote(paste(.(Case),", ",eta[DES]))`. – DeltaIV Dec 11 '15 at 15:15
  • I don't see a reason to use `paste`, but suit yourself. Note how I used `group` in your `ylab`. – Roland Dec 11 '15 at 15:17
  • I didn't notice that. What's the difference between `group` and `paste`? If you have a look at other answers here on Stack Overflow concerning `expression`, using `paste` is often suggested (for example, my `ylab` is taken nearly literally from one of those answers). Other than that, I'm not partial to `paste`, so if you explain me the advantages of `group` or `*`, I'm more than ok with not using `paste`. – DeltaIV Dec 11 '15 at 15:37
  • The difference between `group` and `paste` is explained in the documentation. The output even looks different. – Roland Dec 11 '15 at 17:31