I cannot find a way to write indexes in the header or subheading in R. How can I write v 1,2 with 1,2 as indices?
Thanks for your help!
expression is your friend:
expression
plot(1,1, main=expression('title'^2)) #superscript plot(1,1, main=expression('title'[2])) #subscript
If you want to have multiple indexes in the same text, use an asterisk (*) to separate the sections:
plot(1:10, xlab=expression('hi'[5]*'there'[6]^8*'you'[2]))
See expression
plot(1:10,main=expression("This is a subscript "[2]))
Subscript and referencing stored value ...
a <- 10 plot(c(0,1), c(0,1), type = 'n', ann = FALSE, xaxt = 'n', yaxt = 'n') text(0.2, 0.6, cex = 1.5, bquote(paste('S'['f']*' = ', .(a))))
In another example, the expression works for negative superscripts without the need for quotation marks around a negative number:
title(xlab=expression("Nitrate Loading in kg ha"^-1*"yr"^-1))
and you only need to * separate the sections as described above (when you write a superscript or index and you need to add more text to the expression after).