Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subscripts in R when adding other text

Tags:

r

plotmath

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.

like image 435
Damien Avatar asked Dec 19 '12 15:12

Damien


People also ask

How do I add a subscript to text in R?

Subscripts and Superscripts To indicate a subscript, use the underscore _ character. To indicate a superscript, use a single caret character ^ . Note: this can be confusing, because the R Markdown language delimits superscripts with two carets.

How do you add a superscript in R?

Superscript is “started” by the caret ^ character. Anything after ^ is superscript. The superscript continues until you use a * or ~ character. If you want more text as superscript, then enclose it in quotes.

How do you do subscripts in text?

Use keyboard shortcuts to apply superscript or subscript Select the text or number that you want. For superscript, press Ctrl, Shift, and the Plus sign (+) at the same time. For subscript, press Ctrl and the Equal sign (=) at the same time.

How do you signal a subscript?

Use "_" (underscore) for subscripts. If the subscript has more than one character, enclose it in braces: "lim_{x --> 0} sin (x) / x".


1 Answers

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.

like image 178
IRTFM Avatar answered Oct 21 '22 02:10

IRTFM