2014-08-27 80 views
3

我想添加標題「使用r中的基本繪圖函數從1999年到2008年在美國PM2.5中的排放」。在這方面,我希望2.5是PM的下標。我沒有這樣做,如果PM2.5恰好是字符串的結尾任何問題:r中的標題中的下標

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]) 

但如果是在字符串中間,我不能這樣做。如果我將它分成兩部分,如下所示:

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")) 

由於方括號,我得到一個錯誤,指出意外的符號。

回答

9

試用expressionpaste功能(參見?plotmath瞭解詳細信息),例如:

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

不錯!這工作也爲標籤。 – user3922546 2014-08-27 17:50:11