r 中情节标题中的下标 [英] Subscript in plot title in r

查看:57
本文介绍了r 中情节标题中的下标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加标题从 1999 年到 2008 年美国 PM2.5 的排放",它使用了 r 中的基本绘图函数.在那,我希望 2.5 成为 PM 的下标.如果 PM2.5 恰好在字符串的末尾,我这样做没有任何问题:

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.

推荐答案

尝试 paste 函数用于 expression(详见 ?plotmath),例如:

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

这篇关于r 中情节标题中的下标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆