Chemical formula (or mathematical expression) in GNU R plot title

ⅰ亾dé卋堺 提交于 2020-01-23 02:56:07

问题


How can i write H2o in the title of a plot?

H2 works:

plot(main=expression("H"[2]),0)

H2O fails:

plot(main=expression("H"[2]"O"),0)

This solution will work only, if i have a space in front " "

plot(main=expression(" "*H[2]*"O"),0)

回答1:


You were close. This works:

plot(1:10, main = expression(H[2]*O))

The reason for this is that the 2 is a subscript to element H and you want to position element O next to the H. The notation x * y in an expression means juxtapose x with y, i.e. place x and y together. See ?plotmath for more.



来源:https://stackoverflow.com/questions/13147591/chemical-formula-or-mathematical-expression-in-gnu-r-plot-title

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