Adding greek character to axis title

人走茶凉 提交于 2019-11-27 00:54:55

If you're using plotmath{grDevices}, the main help page (plotmath) contains an example of what you appear to want:

xlab = expression(paste("Phase Angle ", phi))

or for your case, I guess:

ylab = expression(paste("Diameter of aperture ( ", mu, " )"))

Does this work for you?

I think I followed your question properly. The ~ forces a space between characters in a call to expression(). Is this what you want?

plot(1:3, ylab = expression("Diameter of apeture (" * mu ~ "m)"),
  , xlab = expression("Force spaces with ~" ~ mu ~ pi * sigma ~ pi)
  , main = expression("This is another Greek character with space" ~ sigma))

And if you want to substitute variables in the text, use bquote. For instance, if you have a variable mu and want to show it in the title, then use the following idiom:

mu <- 2.8
plot(1:3, main=bquote(mu == .(mu)))

The part enclosed in .() will be substituted, so that the value of mu will be printed and not the greek "mu" character. Consult the R help on bquote for details.

This should be much more straight forward with latex2exp:

require(latex2exp)
plot(1, xlab = TeX('$\\mu$'))

And, in case you were dealing with an estimated quantity, plotmath{grDevices} also offers the possibility of adding a hat to your greek letter:

ylab = expression(paste("Diameter of aperture ( ", hat(mu), " )"))

The mu enclosed in hat() does the trick.

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