Concatenate strings and expressions in a plot's title

Brani picture Brani · Nov 29, 2010 · Viewed 33.6k times · Source

How can I combine text and math expressions in a plot's title. If I use paste the expression is converted to character. For example I want something like this as a title

$ARL_1$ curve for $S^2$

Thank you

Answer

Gavin Simpson picture Gavin Simpson · Nov 29, 2010

You want to read ?plotmath to see how to do this sort of thing. Here is an example:

plot(1:10, main = expression(ARL[1] ~ "curve for" ~ S^2))

The [.] is subscript, whilst ^ gives superscript. The ~ spaces out the parts of the expression as if there were literal spaces.

Edit: normally I would have done:

plot(1:10, main = expression(ARL[1] ~ curve ~ for ~ S^2))

but that throws an error because for is being interpreted as the start of a for() loop call.