Superscript in R

孤街浪徒 提交于 2019-12-04 10:37:11

Whilst I don't see a real problem in this particular instance, I can see if being an issue with other labels. I tend to group the elements of the super/subscript in braces { }, LaTeX stylee.

Here is an example:

plot(1:10,
     ylab = expression("Photosynthetically available radiation" ~ 
                         (µE ~ m^{-2} ~ d^{-1})
                       )
     )

There are gotchas with your version and the one above; the bit in the braces also needs to be a valid expression, hence

plot(1:10,
     ylab = expression("Photosynthetically available radiation" ~ (µE ~ 
                         m^{2-} ~ d^{1-})))

fails with an error. (I sometimes need those forms for writing down formulae for ions for example). To solve this issue you really do need the braces { } and you need something to come after the - operator. This latter feature is handled by phantom(), which leaves space in the expression for its argument, but as we won;t specify one, it is just a placeholder for nothing that can go on the right hand side of -:

plot(1:10,
     ylab = expression("Photosynthetically available radiation" ~ (µE ~ 
                         m^{2-phantom()} ~ d^{1-phantom()})))

phantom() is also quite useful for placing a sub/superscript before a string, like you would with isotope notation

plot(1:10, ylab = expression(phantom()^{210} * Pb))

Two problems I see: There is not sufficient space for the superscripts on the margin and there is no closing right-paren. It's easy enough to add the closing paren with:

ylab=expression("Photosynthetically available radiation (µE m"^-2~d^-1*")"))

(You do need to quote the paren because it is "active" or "special" in expressions. Or you could use the plotmath group-function. The margin is accessible with the par command or you could use the title command to specify a ylab that is closer to the plot:

plot(1,1, ylab="")
title(ylab=expression("Photosynthetically available radiation (µE m"^-2~d^-1*")"),
      line=2)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!