How to include subscript in text for plot point labels

JJS picture JJS · Mar 21, 2013 · Viewed 14.7k times · Source

Hi I'm new to R so I apologise if this is a very basic question. I'm trying to add text to a plot at point 11 on the x axis and point 900 on the y axis that will read t0= -4.0280 with the 0 as subscript. Where t0 <- -4.0280 To do this I've tried:

text(11,900,paste("t[0]=",t0),cex=0.8) 
# which gives 
't[0]= -4.0280'

text(11,900,expression(paste("t[0]=",t0)),cex=0.8) 
# which gives 
't[0]=t0'

# the closest I've gotten is:    
text(11,900,expression(paste(t[0]==t0)),cex=0.8)

which will use subscript but return t0 instead of my value of -4.0280.

Could anyone show me where Ive gone wrong?

Cheers.

Answer

Sven Hohenstein picture Sven Hohenstein · Mar 21, 2013

You can replace expression with substitute. There's no need for the paste. The argument list(t0 = t0) tells substitute to replace the string t0 with the value of the object t0:

plot(1,1)

t0 <- 1.3

text(1, 0.8, substitute(t[0]==t0, list(t0 = t0)), cex = 0.8)

enter image description here