How would you add a subscript to one particular word of a title in R? For example, suppose the title is "A_2 and B_2."
How would you add these two subscripts? I know that expression("A"[2])
and expression("B"[2])
individually add subscripts to these letters.
Asked
Active
Viewed 1.1k times
11
-
3Have you read `?plotmath`? – Roland Dec 19 '12 at 15:07
2 Answers
20
You do not need paste
(or quotes for that matter) at all:
expression( A[2]~and~B[2] )
Test:
plot(1,1, main=expression( A[2]~and~B[2] ) )
The syntactic principle is that tildes (which creates a space) and asterisks (non-space plotmath separator) are used to separate items and that no quotes are needed unless you are using a plotmath function name .... such as wanting the word "paste" or "sqrt" to appear in the displayed version of the expression.

IRTFM
- 258,963
- 21
- 364
- 487
7
Just paste them together:
expression(paste("A"[2], " and B"[2])

blmoore
- 1,487
- 16
- 31
-
2`plot(x, main=expression(paste("A"[2], " and B"[2], sep="")))` (where x is your data...) doesn't work? What device + plot function are you using? – blmoore Dec 19 '12 at 15:25
-
1@Damien, this works using the method described as well as `> plot(x)` `> title(expression(paste("A"[2], " and B"[2], sep="")))` Please doublecheck your implementation – Ricardo Saporta Dec 19 '12 at 15:49
-
1WILL PEOPLE PLEASE STOP USING `sep=` IN PLOTMATH `paste`? (It is not the same function as `base::paste`.) – IRTFM Dec 19 '12 at 18:01