0

I am trying to make a label in a base R plot legend that has a greater than or equal to sign followed by a numeric value that is gathered from a variable. I can do this with the following code using the Unicode character, and the bquote function:

data = c(1,2,3,4)
paste0("\u2265", bquote(.(data[2])))

I would like to know if it is possible to make such a label without the Unicode character, while referencing a variable for a numeric value. I have been unsuccessful using combinations of nested expression, paste, substitute, and bquote function calls, and I have not seen a question here that addresses this specific issue (I apologize if I missed something).

Ideally, the solution would generalize to other plotmath characters as well.

Jared Smith
  • 280
  • 3
  • 12

1 Answers1

1
data = c(1,2,3,4)

plot.new()
text(0.5, 0.5, bquote({} >= .(data[2])), cex = 30)

resulting plot

Roland
  • 127,288
  • 10
  • 191
  • 288
  • What do the curly brackets add? A small space? – Jared Smith Jun 21 '17 at 15:16
  • I think they add nothing but there seems to be a small space added after that nothing. – Roland Jun 21 '17 at 15:20
  • This solves my question as asked, but the result, `≥ 2` cannot be stored in a `list`, like a[1] = `bquote({} >= .(data[2]))`. It is interpreted as 3 elements: {}, >=, and 2, and the `≥` is not one of those elements. I realize this is a different problem, so let me know if I should ask a different question, or add to this question. – Jared Smith Jun 21 '17 at 15:41
  • Create a vector of mode "expression" and store it within that vector. Or I believe a[[1]]] <- ... could also work if you need a list. I can't test right now. – Roland Jun 21 '17 at 17:13
  • I needed to use a vector of mode expression, named `a`, and a[[1]] to get the `≥ 2` to plot correctly. Interestingly, that removes the bold from the ≥, but the 2 is still bold. I'm fine with that, though. Thanks for the help! – Jared Smith Jun 21 '17 at 18:23