0
myfun <- function(x){
  plot(x = 1, y = 1, main = expression(paste(delta, "title ", x)))
}

myfun(3)

I'm using paste to pass in the x variable for my plot title. However, because I also have a mathematical symbol, delta, in the mix, I'm using expression on top of paste. However, this causes the variable x to not appear in the plot title.

Edit:

plot(x = 1, y = 1, main = bquote(paste(delta, "title ", .(x)))) solves the problem!

However, the same approach did not work for boxplot(x = 1, y = 1, main = bquote(paste(delta, "title ", .(x)))).

Adrian
  • 9,229
  • 24
  • 74
  • 132
  • 1
    Try using `bquote` and wrap in `.( )` like this: `plot(x = 1, y = 1, main = bquote(paste(delta, "title ", .(x))))` ... see [this answer](https://stackoverflow.com/a/14074321/3460670)...or [this one](https://stackoverflow.com/questions/4973898/combining-paste-and-expression-functions-in-plot-labels)... – Ben Jun 08 '20 at 02:44
  • Thank you. I was wondering if there's a similar solution for `boxplot` instead of `plot`? I've edited the question. – Adrian Jun 08 '20 at 02:50
  • 1
    `boxplot(...)` (no main), then add `title(bquote(...))`. – r2evans Jun 08 '20 at 03:01
  • 1
    try splitting up the title as suggested [here](https://stackoverflow.com/questions/20549337/expression-and-new-line-in-plot-labels) and by @r2evans – Ben Jun 08 '20 at 03:01
  • 1
    or just `boxplot(1, 1, main = bquote(expression(paste(delta, " title ", .(x)))))` – r2evans Jun 08 '20 at 03:01

0 Answers0