Include formatted subscript in mtext?

谁都会走 提交于 2019-12-22 08:57:25

问题


Admittedly I am new to R but I have looked around quite a bit and I can't seem to solve this.

For superscript this works lovely

mtext(expression(paste( italic("h") ^ italic("2"))), side=2, line = 2, cex=cexm) 

but when I try to get a subscript using the same approach

mtext(expression(paste(italic("I") [] italic("a"))),side=2, line=2,cex=cexm)

or

mtext(expression(paste(italic("I"), italic(["a"]))),side=2, line=2,cex=cexm)

plus several other variations on this theme

R keeps telling me that there is an unexpected [

Any help would be greatly appreciated, apologies if this is addressed elsewhere but I did not succeed in finding it.


回答1:


In the first instance the paste call is entirely superfluous since the argument is a valid R expression:

 mtext(expression( italic("h") ^ italic("2")), side=2, line = 2) # works

In the second instance paste is also unnecessary:

 mtext(expression( italic("I") [italic("a")] ),side=2, line=2,cex=cexm)

The argument to the plotmath-"[" function needs to be inside the paired "[]"-symbols.



来源:https://stackoverflow.com/questions/28664385/include-formatted-subscript-in-mtext

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