Subscript in the header

I would like to add the heading "Emissions from PM2.5 in the United States from 1999 to 2008" which uses a basic plotting function in r. In this I would like 2.5 to be the PM index. I have no problem with this if PM2.5 is at the end of the line:

barplot(height = total.emissions$Emissions, names.arg=total.emissions$year,  
        xlab="Year", ylab= " Amount of emitted in tonsPM"2.5 ,   
        main = "Emissions from in the United States from 1999 to 2008PM"[2.5] )

      

But I cannot do the same if it is in the middle of the line. If I split it into 2 parts like this:

barplot(height = total.emissions$Emissions, names.arg=total.emissions$year,  
        xlab="Year", ylab= " Amount of PM_[2.5] emitted in tons",   
        main = expression("Emissions from PM"[2.5] "in the United States from 1999 to 2008"))

      

I am getting an error with an unexpected character due to square brackets.

+3


source to share


1 answer


Try the function paste

for expression

(see details ?plotmath

), for example:



plot(0, main = expression(paste("Emissions from ", PM[2.5], " in the United States from 1999 to 2008")))

      

+9


source







All Articles