Subscript in plot title in r

亡梦爱人 提交于 2019-12-12 16:26:46

问题


I would like to add the title, " Emissions from PM2.5 in the United States from 1999 to 2008" which uses the base plotting function in r. In that, I would like 2.5 to be a subscript to PM. I don't have any problem doing that if PM2.5 happens to be at the end of the string:

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 can't do the same if it is in the middle of the string. If I split it into 2 parts as follows:

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 get an error saying unexpected symbol because of the square brackets.


回答1:


Try the paste function for expression (see ?plotmath for details), e.g.:

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


来源:https://stackoverflow.com/questions/25531362/subscript-in-plot-title-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!