Search code examples
rtextplotlabelsubscript

Subscripts as variable in plot label


I have n plots with subscript label. Defined labels:

lab<-c("NO[2]","NO","CO[2]","CO")
lab2<-noquote(lab)
plot(1,1,xlab=bquote(.(lab[1])))
plot(1,1,xlab=bquote(.(lab2[1])))

I want this but with .variable

plot(1,1,xlab=bquote(NO[2]))

Any idea?


Solution

  • You have to parse the string.

    plot(1, 1, xlab = bquote(.(parse(text = lab[1]))))
    

    enter image description here