sub- and superscript in plot labels
On Thu, 4 Nov 2004, Gavin Simpson wrote:
Both of the above options produce what I was after. One quick follow-up question regarding the use of phantom(). Looking at ?plotmath phantom leaves space for a character passed as an argument to phantom(), but does not plot it. In the example above we are leaving space for "nothing". I don't understand why this is a valid R expression. I guess phantom() is returning something that makes 2-<returned_val> a valid expression, but I couldn't find the help for ?phantom so I couldn't check on this in the documentation. Also as an aside, phantom() appears, visually, to be a function, but it is not visible to the user as a function. i.e. typing phantom at the prompt yields: Error: Object "phantom" not found. getAnywhere(phantom) yields nothing either. What is phantom() in R parlance?
phantom is not part of the R language, just part of the language that plotmath understands (like frac and scriptstyle). The relevant help page is ?plotmath. As to why it works: phantom() returns an empty box large enough to hold its argument. When given no argument, it returns a very small empty box. In this example the importance of phantom() is that 2-phantom() is parsed as a binary operation, indicating that the - character should be typeset as a minus sign. Writing 2- is a parse error, and writing "2-" indicates that the - character is ordinary text and should be typeset as a hyphen. -thomas